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