mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-09 11:31:58 +00:00
Add shard_connect_timeout parameter for AutoShardedClient
This commit is contained in:
parent
9a1b91dc9f
commit
cb3ea9b889
@ -326,6 +326,11 @@ class AutoShardedClient(Client):
|
|||||||
------------
|
------------
|
||||||
shard_ids: Optional[List[:class:`int`]]
|
shard_ids: Optional[List[:class:`int`]]
|
||||||
An optional list of shard_ids to launch the shards with.
|
An optional list of shard_ids to launch the shards with.
|
||||||
|
shard_connect_timeout: Optional[:class:`float`]
|
||||||
|
The maximum number of seconds to wait before timing out when launching a shard.
|
||||||
|
Defaults to 180 seconds.
|
||||||
|
|
||||||
|
.. versionadded:: 2.4
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -334,6 +339,8 @@ class AutoShardedClient(Client):
|
|||||||
def __init__(self, *args: Any, intents: Intents, **kwargs: Any) -> None:
|
def __init__(self, *args: Any, intents: Intents, **kwargs: Any) -> None:
|
||||||
kwargs.pop('shard_id', None)
|
kwargs.pop('shard_id', None)
|
||||||
self.shard_ids: Optional[List[int]] = kwargs.pop('shard_ids', None)
|
self.shard_ids: Optional[List[int]] = kwargs.pop('shard_ids', None)
|
||||||
|
self.shard_connect_timeout: Optional[float] = kwargs.pop('shard_connect_timeout', 180.0)
|
||||||
|
|
||||||
super().__init__(*args, intents=intents, **kwargs)
|
super().__init__(*args, intents=intents, **kwargs)
|
||||||
|
|
||||||
if self.shard_ids is not None:
|
if self.shard_ids is not None:
|
||||||
@ -411,7 +418,7 @@ class AutoShardedClient(Client):
|
|||||||
async def launch_shard(self, gateway: yarl.URL, shard_id: int, *, initial: bool = False) -> None:
|
async def launch_shard(self, gateway: yarl.URL, shard_id: int, *, initial: bool = False) -> None:
|
||||||
try:
|
try:
|
||||||
coro = DiscordWebSocket.from_client(self, initial=initial, gateway=gateway, shard_id=shard_id)
|
coro = DiscordWebSocket.from_client(self, initial=initial, gateway=gateway, shard_id=shard_id)
|
||||||
ws = await asyncio.wait_for(coro, timeout=180.0)
|
ws = await asyncio.wait_for(coro, timeout=self.shard_connect_timeout)
|
||||||
except Exception:
|
except Exception:
|
||||||
_log.exception('Failed to connect for shard_id: %s. Retrying...', shard_id)
|
_log.exception('Failed to connect for shard_id: %s. Retrying...', shard_id)
|
||||||
await asyncio.sleep(5.0)
|
await asyncio.sleep(5.0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user