gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] 03/03: contrib/scripts/terminate.py.in: indent fix


From: gnunet
Subject: [GNUnet-SVN] [gnunet] 03/03: contrib/scripts/terminate.py.in: indent fixes + comments
Date: Tue, 22 May 2018 11:51:20 +0200

This is an automated email from the git hooks/post-receive script.

ng0 pushed a commit to branch master
in repository gnunet.

commit 2048bc3286e1a6fcaab7a54462d9f61a94d7dc46
Author: Nils Gillmann <address@hidden>
AuthorDate: Tue May 22 09:51:42 2018 +0000

    contrib/scripts/terminate.py.in: indent fixes + comments
    
    Signed-off-by: Nils Gillmann <address@hidden>
---
 contrib/scripts/terminate.py.in | 72 ++++++++++++++++++++++-------------------
 1 file changed, 39 insertions(+), 33 deletions(-)

diff --git a/contrib/scripts/terminate.py.in b/contrib/scripts/terminate.py.in
index 4a6719f38..a1cae5605 100644
--- a/contrib/scripts/terminate.py.in
+++ b/contrib/scripts/terminate.py.in
@@ -20,45 +20,51 @@
 # Utility module that implements safe process termination for W32.
 # For other platforms it's equivalent to Popen.kill ()
 # Requires pywin32 on W32.
+# FIXME: flake8 (python3 version) says, like in many other files:
+#        sys + subprocess are unnecessary imports, not used.
 
 import sys
 import os
 import subprocess
 if os.name == 'nt':
-  import win32api
-  import win32process
+    import win32api
+    import win32process
+
 
 class dummyobj (object):
-  pass
+    pass
+
+
+def safe_terminate_process_by_pid(pid, code):
+    if os.name == 'nt':
+        p = dummyobj()
+        p._handle = win32api.OpenProcess(2 | 1024 | 8 | 32 | 16, 0, pid)
+        result = safe_terminate_process(p, code)
+        win32api.CloseHandle(p._handle)
+        return result
+    else:
+        # XXX (F821): Undefined name 'SIGKILL'
+        return os.kill(int(pid), SIGKILL)
 
-def safe_terminate_process_by_pid (pid, code):
-  if os.name == 'nt':
-    p = dummyobj ()
-    p._handle = win32api.OpenProcess (2 | 1024 | 8 | 32 | 16, 0, pid)
-    result = safe_terminate_process (p, code)
-    win32api.CloseHandle (p._handle)
-    return result
-  else:
-    return os.kill (int (pid), SIGKILL)
 
-def safe_terminate_process (proc, code):
-  if os.name == 'nt':
-    cp = win32api.GetCurrentProcess ()
-    result = False
-    dupproc = win32api.DuplicateHandle (cp, proc._handle, cp, 2 | 1024 | 8 | 
32 | 16, 0, 0)
-    try:
-      exitcode = win32process.GetExitCodeProcess (dupproc)
-      if exitcode == 0x103:
-        kernel32 = win32api.GetModuleHandle ("kernel32")
-        exitprocess = win32api.GetProcAddress (kernel32, "ExitProcess")
-        th, tid = win32process.CreateRemoteThread (dupproc, None, 0, 
exitprocess, code, 0)
-        win32api.CloseHandle (th)
-        result = True
-      else:
-        result = True
-    # except failed to get exit code? failed to get module handle?
-    finally:
-      win32api.CloseHandle (dupproc)
-    return result
-  else:
-    return proc.kill ()
+def safe_terminate_process(proc, code):
+    if os.name == 'nt':
+        cp = win32api.GetCurrentProcess()
+        result = False
+        dupproc = win32api.DuplicateHandle(cp, proc._handle, cp, 2 | 1024 | 8 
| 32 | 16, 0, 0)
+        try:
+            exitcode = win32process.GetExitCodeProcess(dupproc)
+            if exitcode == 0x103:
+                kernel32 = win32api.GetModuleHandle("kernel32")
+                exitprocess = win32api.GetProcAddress(kernel32, "ExitProcess")
+                th, tid = win32process.CreateRemoteThread(dupproc, None, 0, 
exitprocess, code, 0)
+                win32api.CloseHandle(th)
+                result = True
+            else:
+                result = True
+        # except failed to get exit code? failed to get module handle?
+        finally:
+            win32api.CloseHandle(dupproc)
+        return result
+    else:
+        return proc.kill()

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]