Skip to content

Instantly share code, notes, and snippets.

@sublee
Created March 18, 2013 02:19
Show Gist options
  • Save sublee/5184551 to your computer and use it in GitHub Desktop.
Save sublee/5184551 to your computer and use it in GitHub Desktop.
>>> 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