Skip to content

Instantly share code, notes, and snippets.

@minrk
Created August 17, 2012 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minrk/3383348 to your computer and use it in GitHub Desktop.
Save minrk/3383348 to your computer and use it in GitHub Desktop.
Test for gevent sleep bug (affects 0.13, not 1.0)
"""
Test for gevent sleep bug (affects 0.13, not 1.0)
discussed in https://github.com/ipython/ipython/issues/2309
"""
import time
import gevent
def sleeper(duration):
tic = time.time()
gevent.sleep(duration)
toc = time.time()
print "gevent.slept %.1f/%.1fs" % (toc-tic, duration)
return duration
def do_run():
# gevent.sleep(0) # uncomment this to get expected behavior
g1 = gevent.spawn(sleeper, 2) # will be max(2-1.5, 0.2) = 0.5
g2 = gevent.spawn(sleeper, 1) # will be max(1 - 1.5, 0.2) = 0.2
gevent.sleep(0.2) # this gets counted as well
gevent.joinall((g1,g2))
do_run()
print "time.sleeping 0.5s"
time.sleep(0.5)
do_run()
print "time.sleeping 1.0s"
time.sleep(1.0)
do_run()
print "time.sleeping 1.5s"
time.sleep(1.5)
do_run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment