From 2ba921c84d6f41861a019e91722aaea7953645a7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 30 Mar 2020 16:59:22 +0200 Subject: [PATCH] Workaround the occasional delayed stop of a Client instance --- pyrogram/connection/transport/tcp/tcp.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index dbb01946..db1c3ee7 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -19,6 +19,7 @@ import ipaddress import logging import socket +import time try: import socks @@ -72,6 +73,9 @@ class TCP(socks.socksocket): except OSError: pass finally: + # A tiny sleep placed here helps avoiding .recv(n) hanging until the timeout. + # This is a workaround that seems to fix the occasional delayed stop of a client. + time.sleep(0.001) super().close() def recvall(self, length: int) -> bytes or None: