Skip to content

Commit 307f855

Browse files
committed
Check if current thread is the main thread using threading.main_thread()
Signed-off-by: Sebastian Ramacher <sebastian@ramacher.at>
1 parent c58a933 commit 307f855

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@
9999
unicode = str
100100

101101

102+
if sys.version_info >= (3, 4):
103+
def is_main_thread():
104+
return threading.main_thread() == threading.current_thread()
105+
else:
106+
def is_main_thread():
107+
return isinstance(threading.current_thread(), threading._MainThread)
108+
109+
102110
class FakeStdin(object):
103111
"""The stdin object user code will reference
104112
@@ -533,7 +541,7 @@ def __enter__(self):
533541
self.orig_sigwinch_handler = signal.getsignal(signal.SIGWINCH)
534542
self.orig_sigtstp_handler = signal.getsignal(signal.SIGTSTP)
535543

536-
if isinstance(threading.current_thread(), threading._MainThread):
544+
if is_main_thread():
537545
# This turns off resize detection and ctrl-z suspension.
538546
signal.signal(signal.SIGWINCH, self.sigwinch_handler)
539547
signal.signal(signal.SIGTSTP, self.sigtstp_handler)
@@ -550,7 +558,7 @@ def __exit__(self, *args):
550558
sys.stdout = self.orig_stdout
551559
sys.stderr = self.orig_stderr
552560

553-
if isinstance(threading.current_thread(), threading._MainThread):
561+
if is_main_thread():
554562
# This turns off resize detection and ctrl-z suspension.
555563
signal.signal(signal.SIGWINCH, self.orig_sigwinch_handler)
556564
signal.signal(signal.SIGTSTP, self.orig_sigtstp_handler)

0 commit comments

Comments
 (0)