Created
May 9, 2012 15:02
-
-
Save schmir/2645197 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
import gevent | |
from gevent.hub import get_hub | |
lst = [] | |
def _on_async(): | |
oldlen = len(lst) | |
for fun, args, kw in lst[:]: | |
gevent.spawn(fun, *args, **kw) | |
del lst[:oldlen] | |
def call_in_loop(fun, *args, **kw): | |
lst.append((fun, args, kw)) | |
_async.send() | |
_async = get_hub().loop.async(ref=False) | |
_async.start(_on_async) | |
def show(msg): | |
print msg | |
def doit(): | |
import time | |
for i in range(10): | |
time.sleep(0.2) | |
call_in_loop(show, i) | |
import threading | |
t = threading.Thread(target=doit) | |
t.start() | |
gevent.sleep(10) | |
t.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment