Skip to content

Instantly share code, notes, and snippets.

@cfobel
Created April 9, 2013 20:03
Show Gist options
  • Save cfobel/5348900 to your computer and use it in GitHub Desktop.
Save cfobel/5348900 to your computer and use it in GitHub Desktop.
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