mirror of
https://github.com/ceph/ceph
synced 2025-02-09 03:49:38 +00:00
Add a utility for running functions in parallel.
This commit is contained in:
parent
c88ef9e7f7
commit
4b245fce73
27
teuthology/parallel.py
Normal file
27
teuthology/parallel.py
Normal file
@ -0,0 +1,27 @@
|
||||
import gevent
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def run(func, all_args):
|
||||
tasks = []
|
||||
for args in all_args:
|
||||
assert isinstance(args, list), 'args must be a list of lists'
|
||||
tasks.append(gevent.spawn(func, *args))
|
||||
gevent.sleep(0)
|
||||
|
||||
try:
|
||||
while tasks:
|
||||
task = tasks[-1]
|
||||
try:
|
||||
task.get(block=True, timeout=5)
|
||||
except gevent.Timeout:
|
||||
continue
|
||||
else:
|
||||
tasks.pop()
|
||||
except:
|
||||
log.exception('Exception from parallel greenlet')
|
||||
for task in tasks:
|
||||
log.error('KILLING TASK')
|
||||
task.kill(block=True)
|
||||
raise
|
Loading…
Reference in New Issue
Block a user