[Python]How to launch a program using Thread
professionals I know how to launch a command in Linux's terminal via process, sth likes follow开发者_运维百科ing:
import subprocess
subprocess.Popen('ifconfig -a')
But this is opened in process, how can I launch that in a thread instead?
I know "thread.start_new_thread", while this should call a function. Within the function, I still have to use subprocess. And this just to open a process again..
Thank you for your help. Respectfully..
A command like ifconfig
always runs in a separate process. There is no way to run that command within only a "thread" of your application.
Perhaps you could provide more detail about why you believe this is necessary, and we may be able to suggest a different approach. For example, if you need to capture the output of the ifconfig
command, there are certainly ways of doing that within Python.
As you are calling another process outside of your Python application, I think that there is no solution to make it run inside the Python interpreter.
精彩评论