-def kill_process_group(pgid):
- if pgid is None: # Nobody to kill. We don't know who to kill on windows, or we don't have anyone to kill on signal handler
+# Tests whether the process is dead already
+def process_is_dead(pid):
+ try:
+ os.kill(pid, 0)
+ except ProcessLookupError:
+ return True
+ except OSError as err:
+ if err.errno == errno.ESRCH: # ESRCH == No such process. The process is now dead
+ return True
+ return False
+
+# This function send TERM signal + KILL signal after 0.2s to the group of the specified process
+def kill_process_group(pid):
+ if pid is None: # Nobody to kill. We don't know who to kill on windows, or we don't have anyone to kill on signal handler