Skip to content

Commit 052b3a3

Browse files
committed
Re-use is_main_thread
Signed-off-by: Sebastian Ramacher <sebastian@ramacher.at>
1 parent a975340 commit 052b3a3

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

bpython/curtsiesfrontend/coderunner.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import greenlet
1919
import logging
2020

21-
from bpython._py3compat import py3
21+
from bpython._py3compat import py3, is_main_thread
2222
from bpython.config import getpreferredencoding
2323

2424
logger = logging.getLogger(__name__)
@@ -131,18 +131,17 @@ def run_code(self, for_code=None):
131131
if source code is complete, returns "done"
132132
if source code is incomplete, returns "unfinished"
133133
"""
134-
is_main_thread = isinstance(threading.current_thread(), threading._MainThread)
135134
if self.code_context is None:
136135
assert self.source is not None
137136
self.code_context = greenlet.greenlet(self._blocking_run_code)
138-
if is_main_thread:
137+
if is_main_thread():
139138
self.orig_sigint_handler = signal.getsignal(signal.SIGINT)
140139
signal.signal(signal.SIGINT, self.sigint_handler)
141140
request = self.code_context.switch()
142141
else:
143142
assert self.code_is_waiting
144143
self.code_is_waiting = False
145-
if is_main_thread:
144+
if is_main_thread():
146145
signal.signal(signal.SIGINT, self.sigint_handler)
147146
if self.sigint_happened_in_main_context:
148147
self.sigint_happened_in_main_context = False
@@ -161,7 +160,7 @@ def run_code(self, for_code=None):
161160
return False
162161
elif isinstance(request, (Done, Unfinished)):
163162
self._unload_code()
164-
if is_main_thread:
163+
if is_main_thread():
165164
signal.signal(signal.SIGINT, self.orig_sigint_handler)
166165
self.orig_sigint_handler = None
167166
return request

0 commit comments

Comments
 (0)