The following script aims to execute many functions at the same time, but I have no idea why it is not working correctly.
Functions are performed sequentially, and not in parallel.
I would appreciate any suggestion to clarify to me what I am doing wrong.
import time
import eventlet
EXECUTION_TIMEOUT = 10
def example(name, steps_limit):
print 'Starting process %s with %d steps' % (name, steps_limit)
for i in range(1, steps_limit+1):
print "Process %s, step %d" % (name, i)
time.sleep(2)
print 'Finishing process %s with %d steps' % (name, steps_limit)
def fetch(input_data):
example(input_data['name'], input_data['steps'])
test_data = [{'name':'proceso1', 'steps':3},
{'name':'proceso2', 'steps':5},
{'name':'proceso3', 'steps':6},
]
def main():
timeout = eventlet.timeout.Timeout(EXECUTION_TIMEOUT)
pool = eventlet.GreenPool(size=1000)
try:
for hits in pool.imap(fetch, test_data):
pass
except eventlet.Timeout:
print 'Operation interrupted by timeout concept'
finally:
timeout.cancel()
if __name__ == '__main__':
main()
source
share