Skip to content

Instantly share code, notes, and snippets.

@pitrou
Created November 6, 2017 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pitrou/d0ed381729ef9045491263774311e9f0 to your computer and use it in GitHub Desktop.
Save pitrou/d0ed381729ef9045491263774311e9f0 to your computer and use it in GitHub Desktop.
import threading
from tornado import gen
from tornado.concurrent import Future
from tornado.ioloop import IOLoop
fut = Future()
#print("in main:", fut, id(getattr(fut, '_loop', None)))
@gen.coroutine
def f():
loop = IOLoop.current()
loop.call_later(1, fut.set_result, None)
#print("in thread:", id(loop.asyncio_loop), id(getattr(fut, '_loop', None)))
assert (yield fut) is None
t = threading.Thread(target=IOLoop().run_sync, args=(f,))
t.start()
t.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment