Skip to content

Commit 404e31e

Browse files
dup fds for UnixConsole and ad check for closed stdout to flishing, fixes #1
1 parent 1e4186c commit 404e31e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

pyrepl/python_reader.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ def execute(self, text):
192192
self.showsyntaxerror("<input>")
193193
else:
194194
self.runcode(code)
195-
sys.stdout.flush()
195+
if sys.stdout and not sys.stdout.closed:
196+
sys.stdout.flush()
196197

197198
def interact(self):
198199
while 1:
@@ -382,7 +383,7 @@ def main(use_pygame_console=0, interactmethod=default_interactmethod, print_bann
382383
encoding = None
383384
else:
384385
encoding = None # so you get ASCII...
385-
con = UnixConsole(0, 1, None, encoding)
386+
con = UnixConsole(os.dup(0), os.dup(1), None, encoding)
386387
if print_banner:
387388
print("Python", sys.version, "on", sys.platform)
388389
print('Type "help", "copyright", "credits" or "license" '\

pyrepl/readline.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,15 @@ def do(self):
174174
# ____________________________________________________________
175175

176176
class _ReadlineWrapper(object):
177-
f_in = 0
178-
f_out = 1
179177
reader = None
180178
saved_history_length = -1
181179
startup_hook = None
182180
config = ReadlineConfig()
183181

182+
def __init__(self):
183+
self.f_in = os.dup(0)
184+
self.f_ut = os.dup(1)
185+
184186
def get_reader(self):
185187
if self.reader is None:
186188
console = UnixConsole(self.f_in, self.f_out, encoding=ENCODING)

0 commit comments

Comments
 (0)