##// END OF EJS Templates
Try to avoid blocking in read().
Itamar Turner-Trauring -
Show More
@@ -23,6 +23,7 b' import time'
23 23 from ctypes import c_int, POINTER
24 24 from ctypes.wintypes import LPCWSTR, HLOCAL
25 25 from subprocess import STDOUT, TimeoutExpired
26 from threading import Thread
26 27
27 28 # our own imports
28 29 from ._process_common import read_no_interrupt, process_handler, arg_split as py_arg_split
@@ -94,20 +95,25 b' def _find_cmd(cmd):'
94 95 def _system_body(p):
95 96 """Callback for _system."""
96 97 enc = DEFAULT_ENCODING
97 print("READING...")
98 for line in read_no_interrupt(p.stdout).splitlines():
99 line = line.decode(enc, 'replace')
100 print(line, file=sys.stdout)
101 for line in read_no_interrupt(p.stderr).splitlines():
102 line = line.decode(enc, 'replace')
103 print(line, file=sys.stderr)
98
99 def stdout_read():
100 for line in read_no_interrupt(p.stdout).splitlines():
101 line = line.decode(enc, 'replace')
102 print(line, file=sys.stdout)
103
104 def stderr_read():
105 for line in read_no_interrupt(p.stderr).splitlines():
106 line = line.decode(enc, 'replace')
107 print(line, file=sys.stderr)
108
109 Thread(target=stdout_read).start()
110 Thread(target=stderr_read).start()
104 111
105 112 # Wait to finish for returncode. Unfortunately, Python has a bug where
106 113 # wait() isn't interruptible (https://bugs.python.org/issue28168) so poll in
107 114 # a loop instead of just doing `return p.wait()`.
108 115 while True:
109 116 result = p.poll()
110 print("POLLED")
111 117 if result is None:
112 118 time.sleep(0.01)
113 119 else:
General Comments 0
You need to be logged in to leave comments. Login now