Skip to content

Commit c58a933

Browse files
maxnordlundsebastinas
authored andcommitted
Use an if instead of a try statement
1 parent 4ba61b2 commit c58a933

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import subprocess
1212
import sys
1313
import tempfile
14+
import threading
1415
import time
1516
import unicodedata
1617
from six.moves import range
@@ -532,12 +533,10 @@ def __enter__(self):
532533
self.orig_sigwinch_handler = signal.getsignal(signal.SIGWINCH)
533534
self.orig_sigtstp_handler = signal.getsignal(signal.SIGTSTP)
534535

535-
try:
536+
if isinstance(threading.current_thread(), threading._MainThread):
537+
# This turns off resize detection and ctrl-z suspension.
536538
signal.signal(signal.SIGWINCH, self.sigwinch_handler)
537539
signal.signal(signal.SIGTSTP, self.sigtstp_handler)
538-
except ValueError:
539-
pass # Ignore "signal only works in main thread"
540-
# This turns off resize detection and ctrl-z suspension.
541540

542541
self.orig_meta_path = sys.meta_path
543542
if self.watcher:
@@ -551,12 +550,10 @@ def __exit__(self, *args):
551550
sys.stdout = self.orig_stdout
552551
sys.stderr = self.orig_stderr
553552

554-
try:
553+
if isinstance(threading.current_thread(), threading._MainThread):
554+
# This turns off resize detection and ctrl-z suspension.
555555
signal.signal(signal.SIGWINCH, self.orig_sigwinch_handler)
556556
signal.signal(signal.SIGTSTP, self.orig_sigtstp_handler)
557-
except ValueError:
558-
pass # Ignore "signal only works in main thread"
559-
# This turns off resize detection and ctrl-z suspension.
560557

561558
sys.meta_path = self.orig_meta_path
562559

0 commit comments

Comments
 (0)