Created
July 29, 2015 06:42
-
-
Save lacek/41ab2dea749e9d614864 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import gevent | |
from gevent.threadpool import ThreadPool | |
from random import randint | |
def worker(id): | |
print('worker %d working...' % (id)) | |
time = randint(1, 5) | |
gevent.sleep(time) | |
return (id, time) | |
pool = ThreadPool(2) | |
results = pool.imap(worker, xrange(0, 3)) | |
for id, time in results: | |
print('sequential worker %d done for %s seconds' % (id, time)) | |
results = pool.imap(worker, xrange(3,6)) | |
pool.join() | |
for id, time in results: | |
print('batch worker %d done for %s seconds' % (id, time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment