Hi all,
I'm working on a project for which I need to run background network tasks in the background. Since I want to build this on top of IPython, I figured I could tap into the Tornado ioloop that is already used in the IPython Notebook. Yet, I can't seem to find the right way of using the @gen.coroutine calls.
Effectively, what I would like to do is to block on a future. I know I can do this using the `yield` keyword as follows:
@gen.coroutine
def f():
#..
msg = yield recv_future() #this returns a Future object
raise gen.Return(msg)
But the issue is that the function calling this must also use the `yield` syntax, becoming a generator on its own. What I think I need is a way of blocking the current "thread-like" execution on a Future (while the ioloop is still active):
def f():
msg = recv_future().result() #Blocking call
return msg
This is available in the regular coroutine.futures library (
https://docs.python.org/dev/library/concurrent.futures.html#concurrent.futures.Future.result). But when I run use it from within Tornado, I get an exception saying that DummyFuture doesn't support this.
How can I get this "blocking" feature with the Tornado ioloop? I have the coroutine package installed, but still get the "DummyFuture" exception.
PS: I created a GitHub issue for this (
https://github.com/tornadoweb/tornado/issues/1161), but since this is not really a problem with Tornado, but rather with my understanding of it, I'm also posting this. Thanks to @ajdavis for helping me out there.