Created
April 9, 2013 20:03
-
-
Save cfobel/5348900 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import eventlet | |
def defer_f(f, *args, **kwargs): | |
event = eventlet.event.Event() | |
eventlet.spawn_n(f, event, *args, **kwargs) | |
return event | |
def test_long_foo(event, run_count, *args, **kwargs): | |
for i in range(run_count): | |
print '[test_long_foo][%d] %s %s' % (i, args, kwargs) | |
eventlet.sleep(1) | |
result = i | |
event.send(result) | |
def main(): | |
d = defer_f(test_long_foo, 4, 'hello', bar='world') | |
counter = 0 | |
while not d.ready(): | |
print '[main][%d] waiting for test_long_foo' % counter | |
counter += 1 | |
eventlet.sleep(0.1) | |
print d.wait() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment