From 4a5246786ac104fa5b027bacc538b8e59e8acbbc Mon Sep 17 00:00:00 2001 From: lighting9999 <120090117+lighting9999@users.noreply.github.com> Date: Sat, 8 Feb 2025 16:34:55 +0800 Subject: [PATCH 1/2] Fix send_file.py Add a check for conn.recv(1024) to prevent the thread from blocking. --- file_transfer/send_file.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/file_transfer/send_file.py b/file_transfer/send_file.py index 1c56e48f4..8ea8cba11 100644 --- a/file_transfer/send_file.py +++ b/file_transfer/send_file.py @@ -13,6 +13,8 @@ def send_file(filename: str = "mytext.txt", testing: bool = False) -> None: conn, addr = sock.accept() # Establish connection with client. print(f"Got connection from {addr}") data = conn.recv(1024) + if not data: + break #IF NOT data received,the Client has closed the Connection. print(f"Server received: {data = }") with open(filename, "rb") as in_file: From d99e72f4f7e41d058dad638f1b6053d0ee7fb835 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 8 Feb 2025 08:40:47 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- file_transfer/send_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file_transfer/send_file.py b/file_transfer/send_file.py index 8ea8cba11..1084f4fe1 100644 --- a/file_transfer/send_file.py +++ b/file_transfer/send_file.py @@ -14,7 +14,7 @@ def send_file(filename: str = "mytext.txt", testing: bool = False) -> None: print(f"Got connection from {addr}") data = conn.recv(1024) if not data: - break #IF NOT data received,the Client has closed the Connection. + break # IF NOT data received,the Client has closed the Connection. print(f"Server received: {data = }") with open(filename, "rb") as in_file: