Created
March 18, 2013 02:19
-
-
Save sublee/5184551 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
>>> cond = True | |
>>> pause = Pause(lambda: cond) | |
>>> def p1(): | |
... print 'before pause' | |
... pause.wait() | |
... print 'after pause' | |
... | |
>>> def p2(): | |
... global cond, pause | |
... time.sleep(0.5) | |
... print '1st tick' | |
... time.sleep(0.5) | |
... print '2nd tick' | |
... cond = False | |
... time.sleep(0.5) | |
... print '3rd tick' | |
... pause.maybe_resume() | |
... time.sleep(0.5) | |
... print 'done' | |
... | |
>>> gevent.joinall([gevent.spawn(p1), gevent.spawn(p2)]) | |
before pause | |
1st tick | |
2nd tick | |
3rd tick | |
after pause | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment