wxPopen.py
changeset 217 f3eb35df4d87
parent 162 bf3eac08a96b
child 224 aae70ef5af6d
equal deleted inserted replaced
216:11124e129a28 217:f3eb35df4d87
    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 import signal
    31 from signal import SIGTERM, SIGKILL
    32 
    32 
    33     
    33     
    34 class outputThread(threading.Thread):
    34 class outputThread(threading.Thread):
    35     """
    35     """
    36     Thread is used to print the output of a command to the stdout
    36     Thread is used to print the output of a command to the stdout
   137             self.logger.write(self.Command_str + "\n")
   137             self.logger.write(self.Command_str + "\n")
   138             self.logger.write_warning("exited with status %s (pid %s)\n"%(str(ecode),str(pid)))
   138             self.logger.write_warning("exited with status %s (pid %s)\n"%(str(ecode),str(pid)))
   139         if self.finish_callback is not None:
   139         if self.finish_callback is not None:
   140             self.finish_callback(self,ecode,pid)
   140             self.finish_callback(self,ecode,pid)
   141 
   141 
   142     def kill(self):
   142     def kill(self,signal=SIGTERM):
   143         self.outt.killed = True
   143         self.outt.killed = True
   144         self.errt.killed = True
   144         self.errt.killed = True
   145         if wx.Platform == '__WXMSW__':
   145         if wx.Platform == '__WXMSW__':
   146             PROCESS_TERMINATE = 1
   146             PROCESS_TERMINATE = 1
   147             handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.Proc.pid)
   147             handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.Proc.pid)
   148             ctypes.windll.kernel32.TerminateProcess(handle, -1)
   148             ctypes.windll.kernel32.TerminateProcess(handle, -1)
   149             ctypes.windll.kernel32.CloseHandle(handle)
   149             ctypes.windll.kernel32.CloseHandle(handle)
   150         else:
   150         else:
   151             try:
   151             try:
   152                 os.kill(self.Proc.pid, signal.SIGTERM)
   152                 os.kill(self.Proc.pid, signal)
   153             except:
   153             except:
   154                 pass
   154                 pass
   155 
   155 
   156     def spin(self, timeout=None, out_limit=None, err_limit=None, keyword = None, kill_it = True):
   156     def spin(self, timeout=None, out_limit=None, err_limit=None, keyword = None, kill_it = True):
   157         count = 0
   157         count = 0