xterm python subprocess
Posted
by
Quacked Python
on Stack Overflow
See other posts from Stack Overflow
or by Quacked Python
Published on 2012-06-12T16:06:52Z
Indexed on
2012/06/12
16:40 UTC
Read the original article
Hit count: 1419
If using subprocess to execute an xterm on linux, which in turn executes some other process, it seems that Python (2.6.5) will never recognize that the process (xterm) has completed execution.
Consider the following code:
import subprocess
import shlex
import time
proc = subprocess.Popen(shlex.split('xterm -iconic -title "FOO_BAR" -e sleep 5'))
while True:
if proc.poll():
print 'Process completed'
time.sleep(0.1)
This will loop infinitely until you terminate the Python interpreter. I'm guessing that this is probably caused by some oddity with xterm, and not a direct cause of the Python subprocess module, but maybe there are some other smart people out there that could shed some light on the situation.
Note: Calling proc.communicate()
will in fact return when the xterm completes, but for some reason the poll method will not work.
© Stack Overflow or respective owner