tests/killdaemons.py
changeset 43076 2372284d9457
parent 37846 89793289c891
child 45830 c102b704edb5
--- a/tests/killdaemons.py	Sat Oct 05 10:29:34 2019 -0400
+++ b/tests/killdaemons.py	Sun Oct 06 09:45:02 2019 -0400
@@ -7,7 +7,7 @@
 import sys
 import time
 
-if os.name =='nt':
+if os.name == 'nt':
     import ctypes
 
     _BOOL = ctypes.c_long
@@ -46,15 +46,17 @@
         WAIT_TIMEOUT = 258
         WAIT_FAILED = _DWORD(0xFFFFFFFF).value
         handle = ctypes.windll.kernel32.OpenProcess(
-                PROCESS_TERMINATE|SYNCHRONIZE|PROCESS_QUERY_INFORMATION,
-                False, pid)
+            PROCESS_TERMINATE | SYNCHRONIZE | PROCESS_QUERY_INFORMATION,
+            False,
+            pid,
+        )
         if handle is None:
-            _check(0, 87) # err 87 when process not found
-            return # process not found, already finished
+            _check(0, 87)  # err 87 when process not found
+            return  # process not found, already finished
         try:
             r = ctypes.windll.kernel32.WaitForSingleObject(handle, 100)
             if r == WAIT_OBJECT_0:
-                pass # terminated, but process handle still available
+                pass  # terminated, but process handle still available
             elif r == WAIT_TIMEOUT:
                 _check(ctypes.windll.kernel32.TerminateProcess(handle, -1))
             elif r == WAIT_FAILED:
@@ -63,19 +65,21 @@
             # TODO?: forcefully kill when timeout
             #        and ?shorter waiting time? when tryhard==True
             r = ctypes.windll.kernel32.WaitForSingleObject(handle, 100)
-                                                       # timeout = 100 ms
+            # timeout = 100 ms
             if r == WAIT_OBJECT_0:
-                pass # process is terminated
+                pass  # process is terminated
             elif r == WAIT_TIMEOUT:
                 logfn('# Daemon process %d is stuck')
             elif r == WAIT_FAILED:
                 _check(0)  # err stored in GetLastError()
-        except: #re-raises
-            ctypes.windll.kernel32.CloseHandle(handle) # no _check, keep error
+        except:  # re-raises
+            ctypes.windll.kernel32.CloseHandle(handle)  # no _check, keep error
             raise
         _check(ctypes.windll.kernel32.CloseHandle(handle))
 
+
 else:
+
     def kill(pid, logfn, tryhard=True):
         try:
             os.kill(pid, 0)
@@ -94,6 +98,7 @@
             if err.errno != errno.ESRCH:
                 raise
 
+
 def killdaemons(pidfile, tryhard=True, remove=False, logfn=None):
     if not logfn:
         logfn = lambda s: s
@@ -107,8 +112,10 @@
                     if pid <= 0:
                         raise ValueError
                 except ValueError:
-                    logfn('# Not killing daemon process %s - invalid pid'
-                          % line.rstrip())
+                    logfn(
+                        '# Not killing daemon process %s - invalid pid'
+                        % line.rstrip()
+                    )
                     continue
                 pids.append(pid)
         for pid in pids:
@@ -118,9 +125,10 @@
     except IOError:
         pass
 
+
 if __name__ == '__main__':
     if len(sys.argv) > 1:
-        path, = sys.argv[1:]
+        (path,) = sys.argv[1:]
     else:
         path = os.environ["DAEMON_PIDS"]