Getting realtime output from ffmpeg to be used in progress bar (PyQt4, stdout)

In this specific case for capturing ffmpeg’s status output (which goes to STDERR), this SO question solved it for me: FFMPEG and Pythons subprocess The trick is to add universal_newlines=True to the subprocess.Popen() call, because ffmpeg’s output is in fact unbuffered but comes with newline-characters. cmd = “ffmpeg -i in.mp4 -y out.avi” process = subprocess.Popen(cmd, … Read more

Using subprocess wait() and poll()

Both wait() (with timeout specified) and poll() return None if the process has not yet finished, and something different if the process has finished (I think an integer, the exit code, hopefully 0). Edit: wait() and poll() have different behaviors: wait (without the timeout argument) will block and wait for the process to complete. wait … Read more

Break the function after certain time

I think creating a new process may be overkill. If you’re on Mac or a Unix-based system, you should be able to use signal.SIGALRM to forcibly time out functions that take too long. This will work on functions that are idling for network or other issues that you absolutely can’t handle by modifying your function. … Read more

WindowsError [error 5] Access is denied

I solved a similar problem I had by switching to the process directory (I was trying to use inkscape) and it solved my problem import subprocess inkscape_dir=r”C:\Program Files (x86)\Inkscape” assert os.path.isdir(inkscape_dir) os.chdir(inkscape_dir) subprocess.Popen([‘inkscape.exe’,”-f”,fname,”-e”,fname_png]) Maybe switching to the process directory will work for you too.

Performance of subprocess.check_output vs subprocess.call

Reading the docs, both subprocess.call and subprocess.check_output are use-cases of subprocess.Popen. One minor difference is that check_output will raise a Python error if the subprocess returns a non-zero exit status. The greater difference is emphasized in the bit about check_output (my emphasis): The full function signature is largely the same as that of the Popen … Read more

Python subprocess readlines() hangs

I assume you use pty due to reasons outlined in Q: Why not just use a pipe (popen())? (all other answers so far ignore your “NOTE: I don’t want to print out everything at once”). pty is Linux only as said in the docs: Because pseudo-terminal handling is highly platform dependent, there is code to … Read more