Skip to content
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

Allow importing when sys.stdout is reassigned on Python 3 #31

Merged
merged 1 commit into from
Jan 7, 2014

Conversation

takluyver
Copy link
Member

Closes gh-30

sys.stdout.buffer is not guaranteed to exist - e.g. if sys.stdout has been reassigned to an io.StringIO instance, it won't. This is only used by the .interact() method, so it should normally be in interactive cases with 'real' system stdout, but we need at least some fallback for when it isn't - and we certainly need to avoid relying on it at import time.

We should think about the binding order. If sys.stdout is reassigned between importing pexpect and calling the .interact() method, this case (spawn class on Python 3) will pick up the new stdout, but the other cases (spawnu on Python 3, either class on Python 2) won't. However, interact goes on to use direct access to stdout (and stdin) by fileno, so any redirection at the Python level won't be effective anyway.

@jquast
Copy link
Member

jquast commented Jan 7, 2014

ahh, yes. Good catch. A little tricky, but approved ;-)

@takluyver
Copy link
Member Author

Thanks. This did actually come up somewhere in tests I was running, though I can't remember where now.

We should start thinking about a 3.1 release some time soon.

takluyver added a commit that referenced this pull request Jan 7, 2014
Allow importing when sys.stdout is reassigned on Python 3
@takluyver takluyver merged commit 693cb29 into pexpect:master Jan 7, 2014
@takluyver takluyver deleted the stdout-bytes-py3 branch January 8, 2014 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Importing after reassigning sys.stdout fails on Python 3
2 participants