self.shouldStop=False# don't let the main loop stop
self.status=MainExec.STATUS_STARTING
# wait for service to start
foriinrange(0,10):
time.sleep(1.0)
self._procIpcBatch()# pump messages
print("_zz_",end="",flush=True)
ifself.status==MainExec.STATUS_RUNNING:
print("TDengine service READY to process requests")
return# now we've started
raiseRuntimeError("TDengine service did not start successfully")# TODO: handle this better?
defstopTaosService(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("TDengine service process terminated successfully from SIG_INT")
self.subProcess=None
ifself.subProcessand(notself.subProcess.poll()):
print("Sub process is still running... pid = {}".format(self.subProcess.pid))