self.ioThread.daemon=True# thread dies with the program
self.ioThread.start()
self.shouldStop=False# don't let the main loop stop
self.status=MainExec.STATUS_RUNNING
def_stopTaosService(self):
# can be called from both main thread or signal handler
print("Terminating TDengine service running as the sub process...")
# Linux will send Control-C generated SIGINT to the TDengine process already, ref: https://unix.stackexchange.com/questions/176235/fork-and-how-signals-are-delivered-to-processes
ifnotself.subProcess:
print("Process already stopped")
return
retCode=self.subProcess.poll()
ifretCode:# valid return code, process ended
self.subProcess=None
else:# process still alive, let's interrupt it
print("Sub process still running, sending SIG_INT and waiting for it to stop...")
self.subProcess.send_signal(signal.SIGINT)# sub process should end, then IPC queue should end, causing IO thread to end
try:
self.subProcess.wait(10)
exceptsubprocess.TimeoutExpiredaserr:
print("Time out waiting for TDengine service process to exit")
else:
print("Sub process has ended")
self.subProcess=None
ifself.subProcessand(notself.subProcess.poll()):
print("Sub process is still running... pid = {}".format(self.subProcess.pid))