xterm python subprocess
- by Quacked Python
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.