![](/img/trans.png)
[英]Got an error while running an app (ModuleNotFoundError: No module named 'tornado.ioloop')
[英]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
错误。 我觉得这是因为几个正在运行的进程试图访问同一个 Tornado 实例,所以看到了这个错误。 我曾尝试阅读 Tornado 的文档,并在网上看到其他资源试图解决相同的错误,但找不到任何有用的信息。
任何人都可以帮我吗?
这在我from multiprocessing.pool import ThreadPool as Pool
更改为from multiprocessing import Pool
之后起作用了
我曾经将 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.