【发布时间】: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