equal
deleted
inserted
replaced
27 import os |
27 import os |
28 import sys |
28 import sys |
29 import subprocess |
29 import subprocess |
30 import ctypes |
30 import ctypes |
31 from threading import Timer, Lock, Thread, Semaphore |
31 from threading import Timer, Lock, Thread, Semaphore |
32 import wx |
32 import signal |
33 if os.name == 'posix': |
|
34 from signal import SIGTERM, SIGKILL |
|
35 |
33 |
36 |
34 |
37 class outputThread(Thread): |
35 class outputThread(Thread): |
38 """ |
36 """ |
39 Thread is used to print the output of a command to the stdout |
37 Thread is used to print the output of a command to the stdout |
124 "stdin": subprocess.PIPE, |
122 "stdin": subprocess.PIPE, |
125 "stdout": subprocess.PIPE, |
123 "stdout": subprocess.PIPE, |
126 "stderr": subprocess.PIPE |
124 "stderr": subprocess.PIPE |
127 } |
125 } |
128 |
126 |
129 if no_gui and wx.Platform == '__WXMSW__': |
127 if no_gui and os.name in ("nt", "ce"): |
130 self.startupinfo = subprocess.STARTUPINFO() |
128 self.startupinfo = subprocess.STARTUPINFO() |
131 self.startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW |
129 self.startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW |
132 popenargs["startupinfo"] = self.startupinfo |
130 popenargs["startupinfo"] = self.startupinfo |
133 elif wx.Platform == '__WXGTK__': |
131 elif os.name == 'posix': |
134 popenargs["shell"] = False |
132 popenargs["shell"] = False |
135 |
133 |
136 if timeout: |
134 if timeout: |
137 self.timeout = Timer(timeout, self.endlog) |
135 self.timeout = Timer(timeout, self.endlog) |
138 self.timeout.start() |
136 self.timeout.start() |
198 self.startsem.acquire() |
196 self.startsem.acquire() |
199 self.startsem.release() |
197 self.startsem.release() |
200 |
198 |
201 self.outt.killed = True |
199 self.outt.killed = True |
202 self.errt.killed = True |
200 self.errt.killed = True |
203 if wx.Platform == '__WXMSW__': |
201 if os.name in ("nt", "ce"): |
204 PROCESS_TERMINATE = 1 |
202 PROCESS_TERMINATE = 1 |
205 handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.Proc.pid) |
203 handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.Proc.pid) |
206 ctypes.windll.kernel32.TerminateProcess(handle, -1) |
204 ctypes.windll.kernel32.TerminateProcess(handle, -1) |
207 ctypes.windll.kernel32.CloseHandle(handle) |
205 ctypes.windll.kernel32.CloseHandle(handle) |
208 else: |
206 else: |
209 if gently: |
207 if gently: |
210 sig = SIGTERM |
208 sig = signal.SIGTERM |
211 else: |
209 else: |
212 sig = SIGKILL |
210 sig = signal.SIGKILL |
213 try: |
211 try: |
214 os.kill(self.Proc.pid, sig) |
212 os.kill(self.Proc.pid, sig) |
215 except Exception: |
213 except Exception: |
216 pass |
214 pass |
217 self.outt.join() |
215 self.outt.join() |