aboutsummaryrefslogtreecommitdiff
path: root/contrib/scripts
diff options
context:
space:
mode:
authorNils Gillmann <ng0@n0.is>2018-05-22 09:51:42 +0000
committerNils Gillmann <ng0@n0.is>2018-05-22 09:51:42 +0000
commit2048bc3286e1a6fcaab7a54462d9f61a94d7dc46 (patch)
tree89755dcf6c763fc2f1cf2707792d33f8f26ef880 /contrib/scripts
parent067f31e6e330b5348f0979364de7e4038d4594e7 (diff)
downloadgnunet-2048bc3286e1a6fcaab7a54462d9f61a94d7dc46.tar.gz
gnunet-2048bc3286e1a6fcaab7a54462d9f61a94d7dc46.zip
contrib/scripts/terminate.py.in: indent fixes + comments
Signed-off-by: Nils Gillmann <ng0@n0.is>
Diffstat (limited to 'contrib/scripts')
-rw-r--r--contrib/scripts/terminate.py.in72
1 files 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 @@
20# Utility module that implements safe process termination for W32. 20# Utility module that implements safe process termination for W32.
21# For other platforms it's equivalent to Popen.kill () 21# For other platforms it's equivalent to Popen.kill ()
22# Requires pywin32 on W32. 22# Requires pywin32 on W32.
23# FIXME: flake8 (python3 version) says, like in many other files:
24# sys + subprocess are unnecessary imports, not used.
23 25
24import sys 26import sys
25import os 27import os
26import subprocess 28import subprocess
27if os.name == 'nt': 29if os.name == 'nt':
28 import win32api 30 import win32api
29 import win32process 31 import win32process
32
30 33
31class dummyobj (object): 34class dummyobj (object):
32 pass 35 pass
36
37
38def safe_terminate_process_by_pid(pid, code):
39 if os.name == 'nt':
40 p = dummyobj()
41 p._handle = win32api.OpenProcess(2 | 1024 | 8 | 32 | 16, 0, pid)
42 result = safe_terminate_process(p, code)
43 win32api.CloseHandle(p._handle)
44 return result
45 else:
46 # XXX (F821): Undefined name 'SIGKILL'
47 return os.kill(int(pid), SIGKILL)
33 48
34def safe_terminate_process_by_pid (pid, code):
35 if os.name == 'nt':
36 p = dummyobj ()
37 p._handle = win32api.OpenProcess (2 | 1024 | 8 | 32 | 16, 0, pid)
38 result = safe_terminate_process (p, code)
39 win32api.CloseHandle (p._handle)
40 return result
41 else:
42 return os.kill (int (pid), SIGKILL)
43 49
44def safe_terminate_process (proc, code): 50def safe_terminate_process(proc, code):
45 if os.name == 'nt': 51 if os.name == 'nt':
46 cp = win32api.GetCurrentProcess () 52 cp = win32api.GetCurrentProcess()
47 result = False 53 result = False
48 dupproc = win32api.DuplicateHandle (cp, proc._handle, cp, 2 | 1024 | 8 | 32 | 16, 0, 0) 54 dupproc = win32api.DuplicateHandle(cp, proc._handle, cp, 2 | 1024 | 8 | 32 | 16, 0, 0)
49 try: 55 try:
50 exitcode = win32process.GetExitCodeProcess (dupproc) 56 exitcode = win32process.GetExitCodeProcess(dupproc)
51 if exitcode == 0x103: 57 if exitcode == 0x103:
52 kernel32 = win32api.GetModuleHandle ("kernel32") 58 kernel32 = win32api.GetModuleHandle("kernel32")
53 exitprocess = win32api.GetProcAddress (kernel32, "ExitProcess") 59 exitprocess = win32api.GetProcAddress(kernel32, "ExitProcess")
54 th, tid = win32process.CreateRemoteThread (dupproc, None, 0, exitprocess, code, 0) 60 th, tid = win32process.CreateRemoteThread(dupproc, None, 0, exitprocess, code, 0)
55 win32api.CloseHandle (th) 61 win32api.CloseHandle(th)
56 result = True 62 result = True
57 else: 63 else:
58 result = True 64 result = True
59 # except failed to get exit code? failed to get module handle? 65 # except failed to get exit code? failed to get module handle?
60 finally: 66 finally:
61 win32api.CloseHandle (dupproc) 67 win32api.CloseHandle(dupproc)
62 return result 68 return result
63 else: 69 else:
64 return proc.kill () 70 return proc.kill()