Python: How to execute a thread in a new terminal window/command prompt?
How to execute a thread in a script in a new terminal window/command prompt? So that the results of the thread will be displayed on a separate window while still having control on the main interpreter? The thread is a continuous remote server pinging thread for a开发者_开发技巧live check.
The -S
option of xterm
can be used to pass a PTY slave file descriptor. Data written to the corresponding PTY master should then appear in the xterm
window.
So in your thread, you could call os.openpty()
to open a new PTY, start an xterm
with subprocess.Popen()
, passing a suitable -S
option, and write all thread's output to the PTY master fd.
I tried this on Linux but couldn't get any output on the xterm
. Googling around suggests a bug in xterm
, as this is a rarely used feature. Or maybe you can figure out how to do it correctly :)
精彩评论