Problem is that executors must "live" in a class where the io_loop and the executor is defined (this can be seen when you check the @run_on_executor decorator).
def test_executor_future(self):
class Executor():
def __init__(self, io_loop=None):
self.io_loop = io_loop or IOLoop.instance()
self.executor = ThreadPoolExecutor(2)
@tornado.concurrent.run_on_executor
def wait_and_return_a_value(self):
return 20
def destroy(self):
self.executor.shutdown(1)
@tornado.gen.coroutine
def async_compare(callback):
executor = Executor()
val = yield executor.wait_and_return_a_value()
assert_that(val, equal_to(20))
executor.destroy()
callback()
async_compare(self.stop)
self.wait()