mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-29 04:43:45 +03:00
Remove client.disconnected property
This commit is contained in:
parent
bf61dd32af
commit
e524a74b84
|
@ -394,6 +394,12 @@ However, most likely, you were already doing the right thing (or else you would'
|
|||
"why is this not being edited", which you would most likely consider a bug rather than a feature).
|
||||
|
||||
|
||||
The client.disconnected property has been removed
|
||||
-------------------------------------------------
|
||||
|
||||
``client.run_until_disconnected()`` should be used instead.
|
||||
|
||||
|
||||
The TelegramClient is no longer made out of mixins
|
||||
--------------------------------------------------
|
||||
|
||||
|
|
|
@ -301,9 +301,6 @@ def init(
|
|||
def get_loop(self: 'TelegramClient') -> asyncio.AbstractEventLoop:
|
||||
return asyncio.get_event_loop()
|
||||
|
||||
def get_disconnected(self: 'TelegramClient') -> asyncio.Future:
|
||||
return self._sender.disconnected
|
||||
|
||||
def get_flood_sleep_threshold(self):
|
||||
return self._flood_sleep_threshold
|
||||
|
||||
|
|
|
@ -2823,22 +2823,6 @@ class TelegramClient:
|
|||
"""
|
||||
return telegrambaseclient.get_loop(**locals())
|
||||
|
||||
@property
|
||||
def disconnected(self: 'TelegramClient') -> asyncio.Future:
|
||||
"""
|
||||
Property with a ``Future`` that resolves upon disconnection.
|
||||
|
||||
Example
|
||||
.. code-block:: python
|
||||
|
||||
# Wait for a disconnection to occur
|
||||
try:
|
||||
await client.disconnected
|
||||
except OSError:
|
||||
print('Error on disconnect')
|
||||
"""
|
||||
return telegrambaseclient.get_disconnected(**locals())
|
||||
|
||||
@property
|
||||
def flood_sleep_threshold(self):
|
||||
return telegrambaseclient.get_flood_sleep_threshold(**locals())
|
||||
|
@ -2928,30 +2912,26 @@ class TelegramClient:
|
|||
|
||||
def run_until_disconnected(self: 'TelegramClient'):
|
||||
"""
|
||||
Runs the event loop until the library is disconnected.
|
||||
Wait until the library is disconnected.
|
||||
|
||||
It also notifies Telegram that we want to receive updates
|
||||
as described in https://core.telegram.org/api/updates.
|
||||
|
||||
Event handlers will continue to run while the method awaits for a
|
||||
disconnection to occur. Essentially, this method "blocks" until a
|
||||
disconnection occurs, and keeps your code running if you have nothing
|
||||
else to do.
|
||||
|
||||
Manual disconnections can be made by calling `disconnect()
|
||||
<telethon.client.telegrambaseclient.TelegramBaseClient.disconnect>`
|
||||
or sending a ``KeyboardInterrupt`` (e.g. by pressing ``Ctrl+C`` on
|
||||
the console window running the script).
|
||||
or exiting the context-manager using the client (for example, a
|
||||
``KeyboardInterrupt`` by pressing ``Ctrl+C`` on the console window
|
||||
would propagate the error, exit the ``with`` block and disconnect).
|
||||
|
||||
If a disconnection error occurs (i.e. the library fails to reconnect
|
||||
automatically), said error will be raised through here, so you have a
|
||||
chance to ``except`` it on your own code.
|
||||
|
||||
If the loop is already running, this method returns a coroutine
|
||||
that you should await on your own code.
|
||||
|
||||
.. note::
|
||||
|
||||
If you want to handle ``KeyboardInterrupt`` in your code,
|
||||
simply run the event loop in your code too in any way, such as
|
||||
``loop.run_forever()`` or ``await client.disconnected`` (e.g.
|
||||
``loop.run_until_complete(client.disconnected)``).
|
||||
|
||||
Example
|
||||
.. code-block:: python
|
||||
|
||||
|
|
|
@ -18,23 +18,15 @@ if typing.TYPE_CHECKING:
|
|||
Callback = typing.Callable[[typing.Any], typing.Any]
|
||||
|
||||
|
||||
async def _run_until_disconnected(self: 'TelegramClient'):
|
||||
try:
|
||||
# Make a high-level request to notify that we want updates
|
||||
await self(_tl.fn.updates.GetState())
|
||||
return await self.disconnected
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
await self.disconnect()
|
||||
|
||||
async def set_receive_updates(self: 'TelegramClient', receive_updates):
|
||||
self._no_updates = not receive_updates
|
||||
if receive_updates:
|
||||
await self(_tl.fn.updates.GetState())
|
||||
|
||||
async def run_until_disconnected(self: 'TelegramClient'):
|
||||
return await _run_until_disconnected(self)
|
||||
# Make a high-level request to notify that we want updates
|
||||
await self(_tl.fn.updates.GetState())
|
||||
return await self._sender.disconnected
|
||||
|
||||
def on(self: 'TelegramClient', event: EventBuilder):
|
||||
def decorator(f):
|
||||
|
|
Loading…
Reference in New Issue
Block a user