mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-26 03:13:45 +03:00
Add timeout to connect()
This commit is contained in:
parent
e7fac8e254
commit
52a42661ee
|
@ -70,12 +70,14 @@ class TelegramBareClient:
|
||||||
|
|
||||||
# region Connecting
|
# region Connecting
|
||||||
|
|
||||||
def connect(self, exported_auth=None):
|
def connect(self, timeout=timedelta(seconds=5), exported_auth=None):
|
||||||
"""Connects to the Telegram servers, executing authentication if
|
"""Connects to the Telegram servers, executing authentication if
|
||||||
required. Note that authenticating to the Telegram servers is
|
required. Note that authenticating to the Telegram servers is
|
||||||
not the same as authenticating the desired user itself, which
|
not the same as authenticating the desired user itself, which
|
||||||
may require a call (or several) to 'sign_in' for the first time.
|
may require a call (or several) to 'sign_in' for the first time.
|
||||||
|
|
||||||
|
The specified timeout will be used on internal .invoke()'s.
|
||||||
|
|
||||||
If 'exported_auth' is not None, it will be used instead to
|
If 'exported_auth' is not None, it will be used instead to
|
||||||
determine the authorization key for the current session.
|
determine the authorization key for the current session.
|
||||||
"""
|
"""
|
||||||
|
@ -115,13 +117,14 @@ class TelegramBareClient:
|
||||||
query=query)
|
query=query)
|
||||||
|
|
||||||
result = self.invoke(
|
result = self.invoke(
|
||||||
InvokeWithLayerRequest(
|
InvokeWithLayerRequest(layer=layer, query=request),
|
||||||
layer=layer, query=request))
|
timeout=timeout
|
||||||
|
)
|
||||||
|
|
||||||
if exported_auth is not None:
|
if exported_auth is not None:
|
||||||
# TODO Don't actually need this for exported authorizations,
|
# TODO Don't actually need this for exported authorizations,
|
||||||
# they're only valid on such data center.
|
# they're only valid on such data center.
|
||||||
result = self.invoke(GetConfigRequest())
|
result = self.invoke(GetConfigRequest(), timeout=timeout)
|
||||||
|
|
||||||
# We're only interested in the DC options,
|
# We're only interested in the DC options,
|
||||||
# although many other options are available!
|
# although many other options are available!
|
||||||
|
|
|
@ -129,12 +129,14 @@ class TelegramClient(TelegramBareClient):
|
||||||
|
|
||||||
# region Connecting
|
# region Connecting
|
||||||
|
|
||||||
def connect(self, *args):
|
def connect(self, timeout=timedelta(seconds=5), *args):
|
||||||
"""Connects to the Telegram servers, executing authentication if
|
"""Connects to the Telegram servers, executing authentication if
|
||||||
required. Note that authenticating to the Telegram servers is
|
required. Note that authenticating to the Telegram servers is
|
||||||
not the same as authenticating the desired user itself, which
|
not the same as authenticating the desired user itself, which
|
||||||
may require a call (or several) to 'sign_in' for the first time.
|
may require a call (or several) to 'sign_in' for the first time.
|
||||||
|
|
||||||
|
The specified timeout will be used on internal .invoke()'s.
|
||||||
|
|
||||||
*args will be ignored.
|
*args will be ignored.
|
||||||
"""
|
"""
|
||||||
return super(TelegramClient, self).connect()
|
return super(TelegramClient, self).connect()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user