How to fix pyinvoke run() delayed output
Problem
You are using Invoke aka pyinvoke to run shell commands, but the output is delayed: All output will eventually be printed but not exactly at the time when it is generated by the command being run.
Example:
invoke_run_example.py
from invoke import run
run("python myscript.py")Solution
Use pty=True:
invoke_run_fixed.py
run("python myscript.py", pty=True)This will stream the output of the python myscript.py in real-time.
Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow