Skip to content

Pythonista 3.5: Does not reset stdin/stdout/stderr on new script execution #792

Open

Description

@o-murphy

If some script change sys.stdout, sys.stderr, sys.stdin on runtime, there are no reset to original ones on second and future scripts executions. All next executions will use redefined IO, in some cases it won't print nothing. The only way to fix it is reload sys module or restart the app.

Is there way to setup force sys/interpreter/environment reset on next script execution? For now I can avoid it just with adding shortcut to the script with reset environment flag

This behaviour can be represented with this small snippets
Run script1.py and then script2.py

# script1.py
import sys

class FakeStream:
    def write(self, s, no_wait=False):
        pass # assume this stream have no output

print("sample text 1")  # output: sample text 1
sys.stdout = FakeStream()
print("sample text 2")  # No output there
# script2.py
print("sample text 3")  # No more output there till `sys` reload or Pythonista restart

P.S.: For example it happen every time the StaSh launched. It overwrites sys and then neither ansi escape codes will work in the console

Activity

  1. changed the title [-]Pythonista 3.5: Does not reset `stdit/stdout/stderr` on new script execution[/-] [+]Pythonista 3.5: Does not reset `stdin/stdout/stderr` on new script execution[/+] on Aug 19, 2025
  2. omz commented on Aug 29, 2025

    @omz
    Owner

    Good point!

    I guess, being able to overwrite stdout across script launches could be seen as a feature (for customizing Pythonista's output), but in most cases, it would probably make sense to always reset stdout/stderr to the default streams.

  3. o-murphy commented on Aug 29, 2025

    @o-murphy
    Author

    Good point!

    I guess, being able to overwrite stdout across script launches could be seen as a feature (for customizing Pythonista's output), but in most cases, it would probably make sense to always reset stdout/stderr to the default streams.

    I would suggest making this feature optional in the settings. But this possibility must be present.

  4. o-murphy commented on Aug 29, 2025

    @o-murphy
    Author

    Py3.14 adds

    iOS and macOS apps can now be configured to redirect stdout and stderr content to the system log. (Contributed by Russell Keith-Magee in gh-127592.)

    Backported to py3.13?

    This is interesting, but not relevant to this issue discussion subject.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions