首页 > 解决方案 > 类型错误:* 之后的 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

标签: python-3.xmultithreadingdiscord.pypython-asyncio

解决方案


推荐阅读