【问题标题】:asyncio.ensure_future on ElasticBeanstalk (Python 3.6)ElasticBeanstalk 上的 asyncio.ensure_future (Python 3.6)
【发布时间】:2018-10-04 16:38:43
【问题描述】:

我正在尝试使用弹性 beanstalk 来运行 asyncio python 应用程序。 弹性豆茎似乎正在运行 python 3.6.5。

我在尝试从 asyncio 使用 ensure_future 时遇到错误:

module 'asyncio' has no attribute 'ensure_future'

我也尝试了“from asyncio import ensure_future”并得到了导入错误。

我尝试使用 .ebextensions 强制升级 asyncio。 还尝试使用 requirements.txt 强制 asyncio 到我知道适用于我的应用程序的版本(asyncio==3.4.3),但都无济于事。

也试过了

try:
  from asyncio import ensure_future
except ImportError:
  from asyncio import async as ensure_future

然后我在调用 ensure_future 时遇到了错误:

Traceback (most recent call last):
File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File 
"main_async_tasks_crawler.py", line 96, in main
 asyncio.get_event_loop().run_until_complete(ensure_future(async_main()))
 File "/opt/python/run/venv/local/lib/python3.6/site-packages/asyncio/tasks.py", line 516, in async
raise TypeError('A Future or coroutine is required')
TypeError: A Future or coroutine is required                                                                        

我的参数 (async_main()) 是一个异步函数..

我暂时没有想法

【问题讨论】:

  • ensure_future(async_main()) 返回什么?是Future的实例还是协程??
  • 例外是调用 ensure_future (实际上是异步的,因为出于某种原因弹性 beantalk 的 asyncio 版本似乎已经过时并且不想更新) - 并且 async_main() 返回一个等待 - 正如我所说这是一个异步定义。
  • import sys; print(sys.path) 显示什么?不常见到/python3.6/site-packages/asyncio

标签: python-3.x python-asyncio amazon-elastic-beanstalk


【解决方案1】:

asyncio是Python3.6标准库的一部分,不能通过pip安装。

asyncio==3.4.3 真的很老了,当时还没有“async function”这种东西,所以不知道怎么用。

【讨论】:

  • 是的,我实际上只是在做这个,所以我至少在上面呆了 2 个小时。你打败了我,所以你得到了复选标记,谢谢
  • 这不提供解决方案
猜你喜欢
  • 2019-01-10
  • 1970-01-01
  • 1970-01-01
  • 2016-01-31
  • 2018-06-29
  • 1970-01-01
  • 1970-01-01
  • 2020-04-05
  • 2013-06-18
相关资源
最近更新 更多