mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-05 23:04:51 +00:00
Add timeout when connecting
This commit is contained in:
parent
0a6583a43c
commit
52354b93d0
1 changed files with 3 additions and 2 deletions
|
|
@ -25,6 +25,7 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Connection:
|
class Connection:
|
||||||
|
TIMEOUT = 10
|
||||||
MAX_RETRIES = 3
|
MAX_RETRIES = 3
|
||||||
|
|
||||||
MODES = {
|
MODES = {
|
||||||
|
|
@ -49,8 +50,8 @@ class Connection:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
log.info("Connecting...")
|
log.info("Connecting...")
|
||||||
await self.protocol.connect(self.address)
|
await asyncio.wait_for(self.protocol.connect(self.address), Connection.TIMEOUT)
|
||||||
except OSError:
|
except (OSError, asyncio.TimeoutError):
|
||||||
self.protocol.close()
|
self.protocol.close()
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue