猿问

龙卷风:线程不开始在协程中使用@run_on_executor

这个小龙卷风测试存在以下问题:


class SimpleIOLoopTests(tornado.testing.AsyncTestCase):

    def setUp(self):

        super(SimpleIOLoopTests, self).setUp()


    def test_executor_future(self):

        self.executor = ThreadPoolExecutor(2)


        @run_on_executor

        def wait_and_return_a_value():

            time.sleep(2)

            return 20


        @coroutine

        def async_compare(callback):

            val = yield wait_and_return_a_value()

            assert_that(val, equal_to(20))


            callback()


        async_compare(self.stop)

        self.wait()

关键是测试会一直循环直到发生超时。调试代码时,看起来好像执行者-未来是按done()创建的,因此,即使io_loop也不启动它。


我在这里做错了什么?非常感谢您提供有关此问题的帮助


顺便说一句:如果我使用@return_future装饰器(像这样的装饰器)创建一个琐碎的未来,也会发生同样的情况(对于它,已经完成了,这是偶然的事实)


@return_future

    def get_value(callback):

        callback(10)


人到中年有点甜
浏览 306回答 1
1回答
随时随地看视频慕课网APP

相关分类

Python
我要回答