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

Flush each print() call #5

Open
Hephaistos7 opened this issue Apr 22, 2024 · 1 comment
Open

Flush each print() call #5

Hephaistos7 opened this issue Apr 22, 2024 · 1 comment

Comments

@Hephaistos7
Copy link

Hi Alex,
Imagine the following code:
'''
print(1)
print(2)
print(3)
'''

Currently the output from these prints will accumulate in the OutputBuffer and sent according to its function should_flush.
I'm trying to flush immediately after each print().
I would overwrite the should_flush function, but since the Runner class has an instance of the OutputBuffer, I don't know how to overwrite that from the outside without rewriting the OutputBuffer class.

Is there a recommended way of changing the conditions for flushing?

The Big Picture is to build a custom debugger, thus needing to stop execution after each line of code.

Kind regards,
Jeff

@alexmojaki
Copy link
Owner

from python_runner import Runner
from python_runner.output import OutputBuffer


class AlwaysFlushOutput(OutputBuffer):
    def should_flush(self):
        return True


class AlwaysFlushRunner(Runner):
    OutputBufferClass = AlwaysFlushOutput

Or call .flush() on sys.stdout and stderr each time you stop execution.

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

No branches or pull requests

2 participants