def __stop_monitoring(self):
"""Cleanup monitoring threads"""
P = self.program
if P.poll() is None:
raise RuntimeError("Unable to stop monitoring while process {!r} is still running.".format(P))
# stop the update thread
self.eventWorking.clear()
# forcefully close pipes that still open, this should terminate the monitor threads
# also, this fixes a resource leak since python doesn't do this on subprocess death
for p in (P.stdin,P.stdout,P.stderr):
while p and not p.closed:
try: p.close()
except: pass
continue
# join all monitoring threads
map(operator.methodcaller('join'), self.threads)
# now spin until none of them are alive
while len(self.threads) > 0:
for th in self.threads[:]:
if not th.is_alive(): self.__threads.discard(th)
del(th)
continue
# join the updater thread, and then remove it
self.taskQueue.put(None)
self.updater.join()
assert not self.updater.is_alive()
self.__updater = None
return
评论列表
文章目录