Skip to content

Commit a975340

Browse files
committed
Move is_main_thread to bpython._py3compat
Signed-off-by: Sebastian Ramacher <sebastian@ramacher.at>
1 parent 8afce45 commit a975340

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

bpython/_py3compat.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@
3737
from __future__ import absolute_import
3838

3939
import sys
40+
import threading
4041

4142
py3 = (sys.version_info[0] == 3)
4243

44+
4345
if py3:
4446
from pygments.lexers import Python3Lexer as PythonLexer
4547
else:
4648
from pygments.lexers import PythonLexer
4749

50+
4851
if py3 or sys.version_info[:3] >= (2, 7, 3):
4952
def prepare_for_exec(arg, encoding=None):
5053
return arg
@@ -65,3 +68,12 @@ def try_decode(s, encoding):
6568
except UnicodeDecodeError:
6669
return None
6770
return s
71+
72+
73+
if py3:
74+
def is_main_thread():
75+
return threading.main_thread() == threading.current_thread()
76+
else:
77+
def is_main_thread():
78+
return isinstance(threading.current_thread(), threading._MainThread)
79+

bpython/curtsiesfrontend/repl.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from bpython.formatter import BPythonFormatter
3535
from bpython import autocomplete
3636
from bpython.translations import _
37-
from bpython._py3compat import py3
37+
from bpython._py3compat import py3, is_main_thread
3838
from bpython.pager import get_pager_command
3939

4040
from bpython.curtsiesfrontend import replpainter as paint
@@ -99,14 +99,6 @@
9999
unicode = str
100100

101101

102-
if py3:
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-
110102
class FakeStdin(object):
111103
"""The stdin object user code will reference
112104

0 commit comments

Comments
 (0)