我正在尝试使用第 15 页文档中的异步模块运行电报客户端
import telethon
from telethon import TelegramClient, events
import asyncio
client = TelegramClient(USERNAME, API_ID, API_HASH)
async def main():
await client.start()
if __name__ == '__main__':
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
尝试运行时await client.start()
出现以下错误。
Task was destroyed but it is pending!
task: <Task pending coro=<MTProtoSender._send_loop() running at
/home/myuser/.local/lib/python3.5/site-packages/telethon/network/mtprotosender.py:347> wait_for=<Future pending cb=[Task._wakeup()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<MTProtoSender._recv_loop() running at /home/myuser/.local/lib/python3.5/site-packages/telethon/network/mtprotosender.py:411> wait_for=<Future pending cb=[Task._wakeup()]>>
Exception ignored in: <coroutine object MTProtoSender._send_loop at 0x7f27c688b468>
Traceback (most recent call last):
File "/home/myuser/.local/lib/python3.5/site-packages/telethon/network/mtprotosender.py", line 347, in _send_loop
File "/home/myuser/.local/lib/python3.5/site-packages/telethon/network/mtprotosender.py", line 720, in get
File "/usr/lib/python3.5/asyncio/queues.py", line 170, in get
File "/usr/lib/python3.5/asyncio/futures.py", line 227, in cancel
File "/usr/lib/python3.5/asyncio/futures.py", line 242, in _schedule_callbacks
File "/usr/lib/python3.5/asyncio/base_events.py", line 497, in call_soon
File "/usr/lib/python3.5/asyncio/base_events.py", line 506, in _call_soon
File "/usr/lib/python3.5/asyncio/base_events.py", line 334, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending coro=<UpdateMethods._update_loop() running at /home/myuser/.local/lib/python3.5/site-packages/telethon/client/updates.py:206> wait_for=<Future pending cb=[Task._wakeup()]>>
有没有办法在不进入模块代码的情况下解决这个问题,或者我对 asyncio 做错了什么?