Terminate FileForwarder thread on process end
Previously on windows the FileForwarder threads would continue to run and eat up a lot of CPU once the child process they were forwarding dies. This commit shuts down those threads when the child process is killed.
This commit is contained in:
parent
e5e103de6d
commit
482dd2ee33
@ -166,6 +166,14 @@ class Process(RemoteEventHandler):
|
|||||||
raise Exception('Timed out waiting for remote process to end.')
|
raise Exception('Timed out waiting for remote process to end.')
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
|
||||||
|
# Close remote polling threads, otherwise they will spin continuously
|
||||||
|
if hasattr(self, "_stdoutForwarder"):
|
||||||
|
self._stdoutForwarder.finish.set()
|
||||||
|
self._stderrForwarder.finish.set()
|
||||||
|
self._stdoutForwarder.join()
|
||||||
|
self._stderrForwarder.join()
|
||||||
|
|
||||||
self.debugMsg('Child process exited. (%d)' % self.proc.returncode)
|
self.debugMsg('Child process exited. (%d)' % self.proc.returncode)
|
||||||
|
|
||||||
def debugMsg(self, msg, *args):
|
def debugMsg(self, msg, *args):
|
||||||
@ -473,23 +481,24 @@ class FileForwarder(threading.Thread):
|
|||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.color = color
|
self.color = color
|
||||||
|
self.finish = threading.Event()
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.output == 'stdout' and self.color is not False:
|
if self.output == 'stdout' and self.color is not False:
|
||||||
while True:
|
while not self.finish.is_set():
|
||||||
line = self.input.readline()
|
line = self.input.readline()
|
||||||
with self.lock:
|
with self.lock:
|
||||||
cprint.cout(self.color, line, -1)
|
cprint.cout(self.color, line, -1)
|
||||||
elif self.output == 'stderr' and self.color is not False:
|
elif self.output == 'stderr' and self.color is not False:
|
||||||
while True:
|
while not self.finish.is_set():
|
||||||
line = self.input.readline()
|
line = self.input.readline()
|
||||||
with self.lock:
|
with self.lock:
|
||||||
cprint.cerr(self.color, line, -1)
|
cprint.cerr(self.color, line, -1)
|
||||||
else:
|
else:
|
||||||
if isinstance(self.output, str):
|
if isinstance(self.output, str):
|
||||||
self.output = getattr(sys, self.output)
|
self.output = getattr(sys, self.output)
|
||||||
while True:
|
while not self.finish.is_set():
|
||||||
line = self.input.readline()
|
line = self.input.readline()
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.output.write(line)
|
self.output.write(line.decode('utf8'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user