I am trying to write an application that executes subprocesses and (among other things) displays their output in a graphical interface and allows the user to click a button to cancel them. I start such processes as follows:
queue = Queue.Queue(500)
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
iothread = threading.Thread(
target=simple_io_thread,
args=(process.stdout, queue))
iothread.daemon=True
iothread.start()
where simple_io_thread is defined as follows:
def simple_io_thread(pipe, queue):
while True:
line = pipe.readline()
queue.put(line, block=True)
if line=="":
break
. "get" s . , . ( - , , .) terminate , , , I/O . - . . ( , , . , .) I/O , .
- , (< 0,5 ) , - ( ) ) .
, -. , Windows Linux Python 2.6 Tkinter GUI, .
EDIT - , , , , , , , - . , , , , . :
process.stdout.close()
:
IOError: close() called during concurrent operation on the same file object.
... . :
os.close(process.stdout.fileno())
:
close failed in file object destructor: IOError: [Errno 9] Bad file descriptor
... , .