18
18
import greenlet
19
19
import logging
20
20
21
- from bpython ._py3compat import py3
21
+ from bpython ._py3compat import py3 , is_main_thread
22
22
from bpython .config import getpreferredencoding
23
23
24
24
logger = logging .getLogger (__name__ )
@@ -131,18 +131,17 @@ def run_code(self, for_code=None):
131
131
if source code is complete, returns "done"
132
132
if source code is incomplete, returns "unfinished"
133
133
"""
134
- is_main_thread = isinstance (threading .current_thread (), threading ._MainThread )
135
134
if self .code_context is None :
136
135
assert self .source is not None
137
136
self .code_context = greenlet .greenlet (self ._blocking_run_code )
138
- if is_main_thread :
137
+ if is_main_thread () :
139
138
self .orig_sigint_handler = signal .getsignal (signal .SIGINT )
140
139
signal .signal (signal .SIGINT , self .sigint_handler )
141
140
request = self .code_context .switch ()
142
141
else :
143
142
assert self .code_is_waiting
144
143
self .code_is_waiting = False
145
- if is_main_thread :
144
+ if is_main_thread () :
146
145
signal .signal (signal .SIGINT , self .sigint_handler )
147
146
if self .sigint_happened_in_main_context :
148
147
self .sigint_happened_in_main_context = False
@@ -161,7 +160,7 @@ def run_code(self, for_code=None):
161
160
return False
162
161
elif isinstance (request , (Done , Unfinished )):
163
162
self ._unload_code ()
164
- if is_main_thread :
163
+ if is_main_thread () :
165
164
signal .signal (signal .SIGINT , self .orig_sigint_handler )
166
165
self .orig_sigint_handler = None
167
166
return request
0 commit comments