Skip to content

Commit 5619544

Browse files
reset stdin/out/err when reloading sys
fixes bpython#567
1 parent 2c5ada7 commit 5619544

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ def __enter__(self):
524524
sys.meta_path = [ImportFinder(self.watcher, self.orig_meta_path)]
525525

526526
sitefix.monkeypatch_quit()
527+
sitefix.monkeypatch_reload()
527528
return self
528529

529530
def __exit__(self, *args):

bpython/curtsiesfrontend/sitefix.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
import functools
23

34
from six.moves import builtins
45

@@ -16,3 +17,26 @@ def __call__(self, code=None):
1617
def monkeypatch_quit():
1718
if 'site' in sys.modules:
1819
resetquit(builtins)
20+
21+
22+
orig_reload = builtins.reload
23+
24+
25+
def reload(module):
26+
if module is sys:
27+
orig_stdout = sys.stdout
28+
orig_stderr = sys.stderr
29+
orig_stdin = sys.stdin
30+
orig_reload(sys)
31+
sys.stdout = orig_stdout
32+
sys.stderr = orig_stderr
33+
sys.stdin = orig_stdin
34+
else:
35+
builtins.reload(sys)
36+
37+
38+
functools.update_wrapper(reload, orig_reload)
39+
40+
41+
def monkeypatch_reload():
42+
builtins.reload = reload

0 commit comments

Comments
 (0)