script-server icon indicating copy to clipboard operation
script-server copied to clipboard

Python script output doesn't print until script execution finished

Open Alonel opened this issue 5 years ago • 3 comments

I'm running Python scripts which can take a long time to finish running, due to that during the Python execution, print out to the screen the script stages so the users won't need to wait until the end without knowing what's going on. when I'm running vi Script-Server only when Python execution ends I get the complete STDOUT printed to the screen.

I found an ugly workaround which instead of printing out with print(), I'm printing using input() with Timeout of 1 sec before continuing before the user will able to prompt in, and then it prints out the messages in "real-time"

is this a bug or by design?

Alonel avatar Oct 09 '20 22:10 Alonel

Hey, as far as i understand, this is how python buffering works Try running python -u your_script.py

Alonel [email protected] schrieb am Sa., 10. Okt. 2020, 00:22:

I'm running Python scripts which can take a long time to finish running, due to that during the Python execution, print out to the screen the script stages so the users won't need to wait until the end without knowing what's going on. when I'm running vi Script-Server only when Python execution ends I get the complete STDOUT printed to the screen.

I found an ugly workaround which instead of printing out with print(), I'm printing using input() with Timeout of 1 sec before continuing before the user will able to prompt in, and then it prints out the messages in "real-time"

is this a bug or by design?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/bugy/script-server/issues/349, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJXPJKH3L7H4M6FXIRMLEDSJ6ELXANCNFSM4SKSN6BA .

bugy avatar Oct 10 '20 06:10 bugy

Thanks that fix the issue for me.

Alonel avatar Oct 13 '20 14:10 Alonel

I stumbled upon this inconvenience during testing again and decided to disable python buffering for called scripts (using PYTHONUNBUFFERED env variable). Hopefully, it won't break existing functionality and no one relies on buffering

bugy avatar Jul 24 '21 13:07 bugy