svghmi/svghmi_server.py
changeset 3864 3e434edfbfdf
parent 3750 f62625418bff
equal deleted inserted replaced
3863:b076f52bd1c8 3864:3e434edfbfdf
   305 
   305 
   306 
   306 
   307 def waitpid_timeout(proc, helpstr="", timeout = 3):
   307 def waitpid_timeout(proc, helpstr="", timeout = 3):
   308     if proc is None:
   308     if proc is None:
   309         return
   309         return
   310     def waitpid_timeout_loop(pid=proc.pid, timeout = timeout):
   310     def waitpid_timeout_loop(proc = proc, timeout = timeout):
   311         try:
   311         try:
   312             while os.waitpid(pid,os.WNOHANG) == (0,0):
   312             while proc.poll() is None:
   313                 time.sleep(1)
   313                 time.sleep(1)
   314                 timeout = timeout - 1
   314                 timeout = timeout - 1
   315                 if not timeout:
   315                 if not timeout:
   316                     GetPLCObjectSingleton().LogMessage(
   316                     GetPLCObjectSingleton().LogMessage(
   317                         LogLevelsDict["WARNING"], 
   317                         LogLevelsDict["WARNING"], 
   318                         "Timeout waiting for {} PID: {}".format(helpstr, str(pid)))
   318                         "Timeout waiting for {} PID: {}".format(helpstr, str(proc.pid)))
   319                     break
   319                     break
   320         except OSError:
   320         except OSError:
   321             # workaround exception "OSError: [Errno 10] No child processes"
   321             # workaround exception "OSError: [Errno 10] No child processes"
   322             pass
   322             pass
   323     Thread(target=waitpid_timeout_loop, name="Zombie hunter").start()
   323     Thread(target=waitpid_timeout_loop, name="Zombie hunter").start()