Skip to content

reset stdin/out/err when reloading sys #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
reset stdin/out/err when reloading sys
fixes #567
  • Loading branch information
thomasballinger committed Dec 17, 2015
commit 561954415c585e21ad15e5691a54d0888d74b5c0
1 change: 1 addition & 0 deletions bpython/curtsiesfrontend/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ def __enter__(self):
sys.meta_path = [ImportFinder(self.watcher, self.orig_meta_path)]

sitefix.monkeypatch_quit()
sitefix.monkeypatch_reload()
return self

def __exit__(self, *args):
Expand Down
24 changes: 24 additions & 0 deletions bpython/curtsiesfrontend/sitefix.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import functools

from six.moves import builtins

Expand All @@ -16,3 +17,26 @@ def __call__(self, code=None):
def monkeypatch_quit():
if 'site' in sys.modules:
resetquit(builtins)


orig_reload = builtins.reload


def reload(module):
if module is sys:
orig_stdout = sys.stdout
orig_stderr = sys.stderr
orig_stdin = sys.stdin
orig_reload(sys)
sys.stdout = orig_stdout
sys.stderr = orig_stderr
sys.stdin = orig_stdin
else:
builtins.reload(sys)


functools.update_wrapper(reload, orig_reload)


def monkeypatch_reload():
builtins.reload = reload