运行 Tornado 的多个实例给出 ioloop is already 运行 错误

Running multiple instances of Tornado gives ioloop is already running error

这是我的代码的样子,(排除了一些不相关的细节)

from multiprocessing.pool import ThreadPool as Pool

class GetUsers(BaseTask):
    def foo(self):
        pool = Pool()
        try:
            pool.map(self.bar, users)
        finally:
            pool.close()
            pool.join()

    def bar(self, users):
        uuid = users[0]
        ioloopInstance = ioloop.IOLoop().instance()
        isInExperiment = self.isInExperiment(uuid, ioloopInstance)
        log.info(str(uuid)+str(isInExperiment))

    def isInExperiment(self, uuid, ioloop):
        isInExpTag_response =ioloop.run_sync(lambda: self.
                                             fetch_isInExperiment_response(uuid))
        if len(isInExpTag_response.body) > 0:
            return True
        return False

    @gen.coroutine
    def fetch_isInExperiment_response(self, uuid):
        response = yield baz
        raise gen.Return(response)

当我 运行 这个时,我得到 ioloop is already running 错误。 我觉得这是因为多个进程 运行ning 正在尝试访问同一个 Tornado 实例,所以会出现此错误。 我尝试阅读龙卷风的文档并在网上看到其他资源试图解决同样的错误,但找不到任何有用的东西。

谁能帮帮我?

这在我改变后有效 from multiprocessing.pool import ThreadPool as Poolfrom multiprocessing import Pool

我曾经使用 Threadpool 作为解决方法来修复 Can't pickle <type 'instancemethod'> when using multiprocessing Pool.map() this error, but went on to use copy_reg as defined here https://laszukdawid.com/2017/12/13/multiprocessing-in-python-all-about-pickling/ 以解决整个问题。