update from Atlas with major reorg
This commit is contained in:
24
attic/concurrency/parallel/lelo_ex.py
Normal file
24
attic/concurrency/parallel/lelo_ex.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
from time import sleep, time
|
||||
|
||||
from lelo import parallel
|
||||
|
||||
DELAY = .2
|
||||
|
||||
@parallel
|
||||
def loiter(serial, delay):
|
||||
pid = os.getpid()
|
||||
print('%2d pid = %d' % (serial, pid))
|
||||
sleep(delay)
|
||||
return pid
|
||||
|
||||
t0 = time()
|
||||
|
||||
results = []
|
||||
for i in range(15):
|
||||
res = loiter(i, DELAY)
|
||||
results.append(res)
|
||||
|
||||
print('Processes used: ', list(set(results)))
|
||||
|
||||
print('### Elapsed time: %0.2f' % (time() - t0))
|
||||
19
attic/concurrency/parallel/llize.py
Normal file
19
attic/concurrency/parallel/llize.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
from parallelize import parallelize
|
||||
from time import sleep, time
|
||||
|
||||
print('one process:')
|
||||
t0 = time()
|
||||
for i in range(12):
|
||||
print('%2d pid = %d' % (i, os.getpid()))
|
||||
sleep(.2)
|
||||
print('elapsed time: %0.2f' % (time() - t0))
|
||||
|
||||
print()
|
||||
|
||||
print('several processes:')
|
||||
t0 = time()
|
||||
for i in parallelize(range(12)):
|
||||
print('%2d pid = %d' % (i, os.getpid()))
|
||||
sleep(.2)
|
||||
print('elapsed time: %0.2f' % (time() - t0))
|
||||
23
attic/concurrency/parallel/llize_ex.py
Normal file
23
attic/concurrency/parallel/llize_ex.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
from time import sleep, time
|
||||
|
||||
from parallelize import parallelize, per_item
|
||||
|
||||
DELAY = .2
|
||||
|
||||
def loiter(serial, delay):
|
||||
pid = os.getpid()
|
||||
print('%2d pid = %d' % (serial, pid))
|
||||
sleep(delay)
|
||||
return pid
|
||||
|
||||
t0 = time()
|
||||
|
||||
results = []
|
||||
for i in parallelize(range(15), fork=per_item):
|
||||
res = loiter(i, DELAY)
|
||||
results.append(res)
|
||||
|
||||
print('Processes used: ', list(set(results)))
|
||||
|
||||
print('### Elapsed time: %0.2f' % (time() - t0))
|
||||
Reference in New Issue
Block a user