Run Subprocess Inside Python Thread Reading The Output In Realtime
Consider the following Python code: import io import time import subprocess import sys from thread import start_new_thread def ping_function(ip): filename = 'file.log' c
Solution 1:
You should never fork after starting threads. You can thread after starting a fork, so you can have a thread handle the I/O piping, but...
Let me repeat this: You should never fork after starting threads
That article explains it pretty well. You don't have control over the state of your program once you start threads. Especially in Python with things going on in the background.
To fix your code, just start the subprocess from the main thread, then start threading. It's perfectly OK to process the I/O from the pipes in a thread.
Post a Comment for "Run Subprocess Inside Python Thread Reading The Output In Realtime"