[3.13] gh-139391: properly handle signal.signal() in UnixConsole when called from a non-main thread (GH-139392) (#139861)

(cherry picked from commit b8c8b8f1d3)

Co-authored-by: yihong <zouzou0208@gmail.com>
This commit is contained in:
Łukasz Langa 2025-10-09 18:39:23 +01:00 committed by GitHub
parent fa49c2af91
commit 94ff4d4eb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 2 deletions

View file

@ -397,7 +397,12 @@ def restore(self):
os.write(self.output_fd, b"\033[?7h")
if hasattr(self, "old_sigwinch"):
signal.signal(signal.SIGWINCH, self.old_sigwinch)
try:
signal.signal(signal.SIGWINCH, self.old_sigwinch)
except ValueError as e:
import threading
if threading.current_thread() is threading.main_thread():
raise e
del self.old_sigwinch
def push_char(self, char: int | bytes) -> None: