Why does this gevent sleep only take 5 seconds?
I have this bit of code...
import gevent
import datetime as dt
td = dt.datetime.today # alias for convenience only
def f(i):
gevent.sleep(i)
print 'Done %s' %i
return i
jobs = [gevent.spawn(f, 5), gevent.spawn(f, 6), gevent.spawn(f, 7)]
tic = td()
gevent.joinall(jobs)
toc = td()
print (toc - tic)
# or alternatively in ipython
jobs = [gevent.spawn(f, 5), gevent.spawn(f, 6), gevent.spawn(f, 7)]
%time gevent.joinall(jobs)
Why does this only take 5 seconds and all 3 functions resume at once? I
would expect it to block for 7 seconds total, but print at 5, 6, and 7
seconds.
No comments:
Post a Comment