简体   繁体   English

运行多个 Tornado 实例会导致 ioloop 已在运行错误

[英]Running multiple instances of Tornado gives ioloop is already running error

This is how my code looks like, (have excluded some details that aren't really relevant)这就是我的代码的样子,(排除了一些并不真正相关的细节)

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)

When I run this, I get ioloop is already running error.当我运行这个时,我得到ioloop is already running错误。 I feel that this is because several process running are trying to access the same instance of Tornado and so this error is seen.我觉得这是因为几个正在运行的进程试图访问同一个 Tornado 实例,所以看到了这个错误。 I have tried reading the documentation of tornado and seen other resources online trying to tackle the same error, but could not find anything helpful.我曾尝试阅读 Tornado 的文档,并在网上看到其他资源试图解决相同的错误,但找不到任何有用的信息。

Can anyone please help me out?任何人都可以帮我吗?

This worked after I changed from multiprocessing.pool import ThreadPool as Pool to from multiprocessing import Pool这在我from multiprocessing.pool import ThreadPool as Pool更改为from multiprocessing import Pool之后起作用了

I had used to Threadpool as a workaround for fixing 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/ to resolve the entire issue.我曾经将 Threadpool 作为一种解决方法来修复Can't pickle <type 'instancemethod'> when using multiprocessing Pool.map()这个错误,但继续使用这里定义的 copy_reg https://laszukdawid.com/2017/ 12/13/multiprocessing-in-python-all-about-pickling/解决整个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM