python-3.x - 类型错误:* 之后的 asyncio.runners.run() 参数必须是可迭代的,而不是协程
问题描述
我试图从一个文件登录到不同的不和谐令牌,我想对它进行多线程处理以获得更快的方法,但是我在 asyncio 中遇到错误,这是代码
f = open("tokens.txt", "r")
lines = f.readlines()
for line in lines:
print(type(line), line)
async def hosting(token):
bot = discord.Client()
await bot.login(token)
print(f"Connected as: {token}")
async def do_something_important():
await print(10)
if __name__ == "__main__":
for token in lines:
_thread = threading.Thread(target=asyncio.run, args=(hosting(token)))
_thread.start()
和回溯:
File "C:\Users\iuli2\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
File "C:\Users\iuli2\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
File "C:\Users\iuli2\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
Traceback (most recent call last):
File "C:\Users\iuli2\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
File "C:\Users\iuli2\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
File "C:\Users\iuli2\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
C:\Users\iuli2\AppData\Local\Programs\Python\Python39\lib\threading.py:914: RuntimeWarning: coroutine 'hosting' was never awaited
del self._target, self._args, self._kwargs
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
self.run()
File "C:\Users\iuli2\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
TypeError: asyncio.runners.run() argument after * must be an iterable, not coroutine
self._target(*self._args, **self._kwargs)
TypeError: asyncio.runners.run() argument after * must be an iterable, not coroutine
解决方案
推荐阅读
- javascript - 如何确定 HTML 文本是否使用图标字体?
- angular - 在单元测试角度处理设置超时
- swift - 将运行脚本生成的文件添加到Xcode中的测试目标编译列表中
- google-apps-script - 在应用程序脚本中创建一个简单的确认框以在我的 html 中弹出
- javascript - 想要在 jspdf 中操作样式属性
- php - 在 Sanctum 和 React 中进行身份验证
- postgresql - postgres autovacuum 计数过高
- angular - 角日期管道 'YYYY' 不匹配 'full'
- blockchain - Pancakeswap liqidty 不适用于分叉令牌
- python - 从图中提取值