![](/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.