[英]RunTimeError in Twint : This event loop is already running
我使用 jupyter 筆記本並運行 twint。
代碼
c = twint.Config()
c.Username = 'twitter'
c.Limit = 20
twint.run.Followers(c)
上述命令會產生與(我相信)試圖創建 2 個異步事件循環的代碼相關的運行時錯誤。 回溯如下:
RuntimeError Traceback (most recent call last)
<ipython-input-4-4713cc05fb59> in <module>()
----> 1 twint.run.Favorites(c)
~/coding/tools/twint/twint/run.py in Favorites(config)
119 def Favorites(config):
120 config.Favorites = True
--> 121 run(config)
122
123 def Followers(config):
~/coding/tools/twint/twint/run.py in run(config)
115
116 def run(config):
--> 117 get_event_loop().run_until_complete(Twint(config).main())
118
119 def Favorites(config):
~/.pyenv/versions/3.6.5/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future)
453 future.add_done_callback(_run_until_complete_cb)
454 try:
--> 455 self.run_forever()
456 except:
457 if new_task and future.done() and not future.cancelled():
~/.pyenv/versions/3.6.5/lib/python3.6/asyncio/base_events.py in run_forever(self)
407 self._check_closed()
408 if self.is_running():
--> 409 raise RuntimeError('This event loop is already running')
410 if events._get_running_loop() is not None:
411 raise RuntimeError(
RuntimeError: This event loop is already running
我找到了使用 nest_async 的 Jupyter 筆記本的解決方案
簡單地做
pip install nest_asyncio
並添加這些行。
import nest_asyncio
nest_asyncio.apply()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.