wxPopen.py
changeset 235 a66e150f2888
parent 232 83cc1a306560
child 361 331d698e1118
equal deleted inserted replaced
234:aff053bad924 235:a66e150f2888
    26 import time
    26 import time
    27 import wx
    27 import wx
    28 import subprocess, ctypes
    28 import subprocess, ctypes
    29 import threading
    29 import threading
    30 import os
    30 import os
    31 from signal import SIGTERM
    31 if os.name == 'posix':
       
    32     from signal import SIGTERM, SIGKILL
    32 
    33 
    33     
    34     
    34 class outputThread(threading.Thread):
    35 class outputThread(threading.Thread):
    35     """
    36     """
    36     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
   138         if self.exitcode != 0:
   139         if self.exitcode != 0:
   139             wx.CallAfter(self.log_the_end,ecode,pid)
   140             wx.CallAfter(self.log_the_end,ecode,pid)
   140         if self.finish_callback is not None:
   141         if self.finish_callback is not None:
   141             self.finish_callback(self,ecode,pid)
   142             self.finish_callback(self,ecode,pid)
   142 
   143 
   143     def kill(self,signal=SIGTERM):
   144     def kill(self,gently=True):
   144         self.outt.killed = True
   145         self.outt.killed = True
   145         self.errt.killed = True
   146         self.errt.killed = True
   146         if wx.Platform == '__WXMSW__':
   147         if wx.Platform == '__WXMSW__':
   147             PROCESS_TERMINATE = 1
   148             PROCESS_TERMINATE = 1
   148             handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.Proc.pid)
   149             handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.Proc.pid)
   149             ctypes.windll.kernel32.TerminateProcess(handle, -1)
   150             ctypes.windll.kernel32.TerminateProcess(handle, -1)
   150             ctypes.windll.kernel32.CloseHandle(handle)
   151             ctypes.windll.kernel32.CloseHandle(handle)
   151         else:
   152         else:
       
   153             if gently:
       
   154                 sig=SIGTERM
       
   155             else:
       
   156                 sig=SIGKILL
   152             try:
   157             try:
   153                 os.kill(self.Proc.pid, signal)
   158                 os.kill(self.Proc.pid, sig)
   154             except:
   159             except:
   155                 pass
   160                 pass
   156         self.outt.join()
   161         self.outt.join()
   157         self.errt.join()
   162         self.errt.join()
   158 
   163