Created
August 17, 2012 23:03
-
-
Save minrk/3383348 to your computer and use it in GitHub Desktop.
Test for gevent sleep bug (affects 0.13, not 1.0)
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
""" | |
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