Created
January 23, 2015 13:01
-
-
Save neta79/3943d55ca7eedf716ed6 to your computer and use it in GitHub Desktop.
Use multiprocessing worker with Tornado IOLoop
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 time | |
from concurrent.futures import ProcessPoolExecutor | |
from tornado.ioloop import IOLoop | |
from tornado import gen | |
def f(a, b, c, blah=None): | |
print "got %s %s %s and %s" % (a, b, c, blah) | |
time.sleep(5) | |
return "hey there" | |
@gen.coroutine | |
def test_it(): | |
pool = ProcessPoolExecutor(max_workers=1) | |
fut = pool.submit(f, 1, 2, 3, blah="ok") # This returns a concurrent.futures.Future | |
print("running it asynchronously") | |
ret = yield fut | |
print("it returned %s" % ret) | |
pool.shutdown() | |
IOLoop.instance().run_sync(test_it) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment