Skip to content

Commit 2ba921c

Browse files
committed
Workaround the occasional delayed stop of a Client instance
1 parent b9c50b0 commit 2ba921c

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

  • pyrogram/connection/transport/tcp

pyrogram/connection/transport/tcp/tcp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import ipaddress
2020
import logging
2121
import socket
22+
import time
2223

2324
try:
2425
import socks
@@ -72,6 +73,9 @@ def close(self):
7273
except OSError:
7374
pass
7475
finally:
76+
# A tiny sleep placed here helps avoiding .recv(n) hanging until the timeout.
77+
# This is a workaround that seems to fix the occasional delayed stop of a client.
78+
time.sleep(0.001)
7579
super().close()
7680

7781
def recvall(self, length: int) -> bytes or None:

0 commit comments

Comments
 (0)