mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-09 13:29:47 +00:00
Get rid of client.loop
Instead, use the asyncio-intended way of implicit loop.
This commit is contained in:
@@ -134,12 +134,13 @@ async def main():
|
||||
|
||||
|
||||
# By default, `Quart.run` uses `asyncio.run()`, which creates a new asyncio
|
||||
# event loop. If we create the `TelegramClient` before, `telethon` will
|
||||
# use `asyncio.get_event_loop()`, which is the implicit loop in the main
|
||||
# thread. These two loops are different, and it won't work.
|
||||
# event loop. Instead, we use `asyncio.run()` manually in order to make this
|
||||
# explicit, as the client cannot be "transferred" between loops while
|
||||
# connected due to the need to schedule work within an event loop.
|
||||
#
|
||||
# So, we have to manually pass the same `loop` to both applications to
|
||||
# make 100% sure it works and to avoid headaches.
|
||||
# In essence one needs to be careful to avoid mixing event loops, but this is
|
||||
# simple, as `asyncio.run` is generally only used in the entry-point of the
|
||||
# program.
|
||||
#
|
||||
# To run Quart inside `async def`, we must use `hypercorn.asyncio.serve()`
|
||||
# directly.
|
||||
@@ -149,4 +150,4 @@ async def main():
|
||||
# won't have to worry about any of this, but it's still good to be
|
||||
# explicit about the event loop.
|
||||
if __name__ == '__main__':
|
||||
client.loop.run_until_complete(main())
|
||||
asyncio.run(main())
|
||||
|
Reference in New Issue
Block a user