wxPopen.py
author etisserant
Mon, 23 Jun 2008 16:06:20 +0200
changeset 162 bf3eac08a96b
parent 154 f3134b2c6d92
child 217 f3eb35df4d87
permissions -rw-r--r--
Try to fix strange wxPopen behavior. Feedback appreciated.
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
     1
#!/usr/bin/env python
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
     2
# -*- coding: utf-8 -*-
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
     3
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
     4
#This file is part of Beremiz, a Integrated Development Environment for
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
     5
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. 
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
     6
#
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
     8
#
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
     9
#See COPYING file for copyrights details.
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    10
#
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    11
#This library is free software; you can redistribute it and/or
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    12
#modify it under the terms of the GNU General Public
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    13
#License as published by the Free Software Foundation; either
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    15
#
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    16
#This library is distributed in the hope that it will be useful,
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    19
#General Public License for more details.
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    20
#
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    21
#You should have received a copy of the GNU General Public
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    22
#License along with this library; if not, write to the Free Software
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    24
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    25
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    26
import time
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    27
import wx
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    28
import subprocess, ctypes
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    29
import threading
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    30
import os
154
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
    31
import signal
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    32
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    33
    
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    34
class outputThread(threading.Thread):
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    35
    """
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    36
    Thread is used to print the output of a command to the stdout
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    37
    """
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    38
    def __init__(self, Proc, fd, callback=None, endcallback=None):
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    39
        threading.Thread.__init__(self)
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    40
        self.killed = False
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    41
        self.finished = False
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    42
        self.retval = None
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    43
        self.Proc = Proc
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    44
        self.callback = callback
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    45
        self.endcallback = endcallback
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    46
        self.fd = fd
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    47
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    48
    def run(self):
162
bf3eac08a96b Try to fix strange wxPopen behavior. Feedback appreciated.
etisserant
parents: 154
diff changeset
    49
        outchunk = None
149
fc7fe0de9143 Tried to fix Linux behaviour of wxPopen.py
etisserant
parents: 130
diff changeset
    50
        self.retval = None
162
bf3eac08a96b Try to fix strange wxPopen behavior. Feedback appreciated.
etisserant
parents: 154
diff changeset
    51
        while outchunk != '' and not self.killed :
bf3eac08a96b Try to fix strange wxPopen behavior. Feedback appreciated.
etisserant
parents: 154
diff changeset
    52
            outchunk = self.fd.readline()
bf3eac08a96b Try to fix strange wxPopen behavior. Feedback appreciated.
etisserant
parents: 154
diff changeset
    53
            if self.callback : self.callback(outchunk)
149
fc7fe0de9143 Tried to fix Linux behaviour of wxPopen.py
etisserant
parents: 130
diff changeset
    54
        while self.retval is None and not self.killed :
fc7fe0de9143 Tried to fix Linux behaviour of wxPopen.py
etisserant
parents: 130
diff changeset
    55
            self.retval = self.Proc.poll()
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    56
            outchunk = self.fd.readline()
162
bf3eac08a96b Try to fix strange wxPopen behavior. Feedback appreciated.
etisserant
parents: 154
diff changeset
    57
            if self.callback : self.callback(outchunk)
bf3eac08a96b Try to fix strange wxPopen behavior. Feedback appreciated.
etisserant
parents: 154
diff changeset
    58
        while outchunk != '' and not self.killed :
bf3eac08a96b Try to fix strange wxPopen behavior. Feedback appreciated.
etisserant
parents: 154
diff changeset
    59
            outchunk = self.fd.readline()
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    60
        if self.endcallback:
130
9af34a1d33b7 fixed short process wainting bug. Seems wait() fail when process already finisshed... TO BE CONFIRMED.
greg
parents: 128
diff changeset
    61
            try:
9af34a1d33b7 fixed short process wainting bug. Seems wait() fail when process already finisshed... TO BE CONFIRMED.
greg
parents: 128
diff changeset
    62
            	err = self.Proc.wait()
9af34a1d33b7 fixed short process wainting bug. Seems wait() fail when process already finisshed... TO BE CONFIRMED.
greg
parents: 128
diff changeset
    63
            except:
149
fc7fe0de9143 Tried to fix Linux behaviour of wxPopen.py
etisserant
parents: 130
diff changeset
    64
                err = self.retval
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    65
            self.finished = True
149
fc7fe0de9143 Tried to fix Linux behaviour of wxPopen.py
etisserant
parents: 130
diff changeset
    66
            wx.CallAfter(self.endcallback, self.Proc.pid, err)
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
    67
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    68
class ProcessLogger:
111
e2e498333fbc fixed display/hide console when launch external programs
greg
parents: 110
diff changeset
    69
    def __init__(self, logger, Command, finish_callback=None, no_stdout=False, no_stderr=False, no_gui=True):
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    70
        self.logger = logger
154
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
    71
        self.Command_str = Command
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
    72
        self.Command = []
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
    73
        for i,word in enumerate(Command.replace("'",'"').split('"')):
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
    74
            if i % 2 == 0:
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
    75
                word = word.strip()
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
    76
                if len(word) > 0:
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
    77
                    self.Command.extend(word.split())
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
    78
            else:
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
    79
                self.Command.append(word)
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
    80
        
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    81
        self.finish_callback = finish_callback
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    82
        self.no_stdout = no_stdout
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    83
        self.no_stderr = no_stderr
111
e2e498333fbc fixed display/hide console when launch external programs
greg
parents: 110
diff changeset
    84
        self.startupinfo = None
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    85
        self.errlen = 0
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    86
        self.outlen = 0
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    87
        self.exitcode = None
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    88
        self.outdata = ""
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    89
        self.errdata = ""
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
    90
        self.finished = False
111
e2e498333fbc fixed display/hide console when launch external programs
greg
parents: 110
diff changeset
    91
        
128
3db703a78e9c fixed subprocess launching on linux (avoid use of undefied self.startupinfo and use use Shell=True (bash will split arguments))
greg
parents: 112
diff changeset
    92
        popenargs= {
3db703a78e9c fixed subprocess launching on linux (avoid use of undefied self.startupinfo and use use Shell=True (bash will split arguments))
greg
parents: 112
diff changeset
    93
               "cwd":os.getcwd(),
3db703a78e9c fixed subprocess launching on linux (avoid use of undefied self.startupinfo and use use Shell=True (bash will split arguments))
greg
parents: 112
diff changeset
    94
               "stdin":subprocess.PIPE, 
3db703a78e9c fixed subprocess launching on linux (avoid use of undefied self.startupinfo and use use Shell=True (bash will split arguments))
greg
parents: 112
diff changeset
    95
               "stdout":subprocess.PIPE, 
3db703a78e9c fixed subprocess launching on linux (avoid use of undefied self.startupinfo and use use Shell=True (bash will split arguments))
greg
parents: 112
diff changeset
    96
               "stderr":subprocess.PIPE}
111
e2e498333fbc fixed display/hide console when launch external programs
greg
parents: 110
diff changeset
    97
        if no_gui == True and wx.Platform == '__WXMSW__':
e2e498333fbc fixed display/hide console when launch external programs
greg
parents: 110
diff changeset
    98
            self.startupinfo = subprocess.STARTUPINFO()
e2e498333fbc fixed display/hide console when launch external programs
greg
parents: 110
diff changeset
    99
            self.startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
128
3db703a78e9c fixed subprocess launching on linux (avoid use of undefied self.startupinfo and use use Shell=True (bash will split arguments))
greg
parents: 112
diff changeset
   100
            popenargs["startupinfo"] = self.startupinfo
3db703a78e9c fixed subprocess launching on linux (avoid use of undefied self.startupinfo and use use Shell=True (bash will split arguments))
greg
parents: 112
diff changeset
   101
        elif wx.Platform == '__WXGTK__':
154
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
   102
            popenargs["shell"] = False  #True
111
e2e498333fbc fixed display/hide console when launch external programs
greg
parents: 110
diff changeset
   103
        
128
3db703a78e9c fixed subprocess launching on linux (avoid use of undefied self.startupinfo and use use Shell=True (bash will split arguments))
greg
parents: 112
diff changeset
   104
        self.Proc = subprocess.Popen( self.Command, **popenargs )
112
fa0eaeaa9012 Re-enabled stderr
etisserant
parents: 111
diff changeset
   105
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   106
        self.outt = outputThread(
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   107
                      self.Proc,
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   108
                      self.Proc.stdout,
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   109
                      self.output,
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   110
                      self.finish)
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
   111
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   112
        self.outt.start()
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
   113
112
fa0eaeaa9012 Re-enabled stderr
etisserant
parents: 111
diff changeset
   114
        self.errt = outputThread(
fa0eaeaa9012 Re-enabled stderr
etisserant
parents: 111
diff changeset
   115
                      self.Proc,
fa0eaeaa9012 Re-enabled stderr
etisserant
parents: 111
diff changeset
   116
                      self.Proc.stderr,
fa0eaeaa9012 Re-enabled stderr
etisserant
parents: 111
diff changeset
   117
                      self.errors)
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   118
#
128
3db703a78e9c fixed subprocess launching on linux (avoid use of undefied self.startupinfo and use use Shell=True (bash will split arguments))
greg
parents: 112
diff changeset
   119
        self.errt.start()	
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
   120
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   121
    def output(self,v):
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   122
        self.outdata += v
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   123
        self.outlen += 1
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   124
        if not self.no_stdout:
151
43614ea83d2a still enhancing Linux behavior of wxPopen
etisserant
parents: 149
diff changeset
   125
            wx.CallAfter(self.logger.write,v)
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
   126
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   127
    def errors(self,v):
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   128
        self.errdata += v
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   129
        self.errlen += 1
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   130
        if not self.no_stderr:
151
43614ea83d2a still enhancing Linux behavior of wxPopen
etisserant
parents: 149
diff changeset
   131
            wx.CallAfter(self.logger.write_warning,v)
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
   132
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   133
    def finish(self, pid,ecode):
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   134
        self.finished = True
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   135
        self.exitcode = ecode
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   136
        if self.exitcode != 0:
154
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
   137
            self.logger.write(self.Command_str + "\n")
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   138
            self.logger.write_warning("exited with status %s (pid %s)\n"%(str(ecode),str(pid)))
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   139
        if self.finish_callback is not None:
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   140
            self.finish_callback(self,ecode,pid)
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
   141
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
   142
    def kill(self):
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   143
        self.outt.killed = True
112
fa0eaeaa9012 Re-enabled stderr
etisserant
parents: 111
diff changeset
   144
        self.errt.killed = True
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   145
        if wx.Platform == '__WXMSW__':
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   146
            PROCESS_TERMINATE = 1
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   147
            handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.Proc.pid)
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   148
            ctypes.windll.kernel32.TerminateProcess(handle, -1)
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   149
            ctypes.windll.kernel32.CloseHandle(handle)
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   150
        else:
154
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
   151
            try:
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
   152
                os.kill(self.Proc.pid, signal.SIGTERM)
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
   153
            except:
f3134b2c6d92 Fixed killing app on Linux in wxPopen. Do not use shell anymore. Command line is splitted into args, taking care of double and simple cotes. To be tested on win32.
etisserant
parents: 151
diff changeset
   154
                pass
79
ae06c2da83f7 Some window related enhancements
etisserant
parents: 70
diff changeset
   155
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   156
    def spin(self, timeout=None, out_limit=None, err_limit=None, keyword = None, kill_it = True):
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   157
        count = 0
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   158
        while not self.finished:
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   159
            if err_limit and self.errlen > err_limit:
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   160
                break
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   161
            if out_limit and self.outlen > out_limit:
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   162
                break
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   163
            if timeout:
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   164
                if count > timeout:
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   165
                    break
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   166
                count += 1
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   167
            if keyword and self.outdata.find(keyword)!=-1:
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   168
                    break
89
0ab2868c6aa6 Added right aligment of parameteres blocks
etisserant
parents: 79
diff changeset
   169
            wx.Yield()
0ab2868c6aa6 Added right aligment of parameteres blocks
etisserant
parents: 79
diff changeset
   170
            time.sleep(0.01)
0ab2868c6aa6 Added right aligment of parameteres blocks
etisserant
parents: 79
diff changeset
   171
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   172
        if not self.outt.finished and kill_it:
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   173
            self.kill()
89
0ab2868c6aa6 Added right aligment of parameteres blocks
etisserant
parents: 79
diff changeset
   174
110
a05e8b30c024 Fixed way apps are launched in parralel with single log window... Tested in win32 only.
etisserant
parents: 89
diff changeset
   175
        return [self.exitcode, self.outdata, self.errdata]
89
0ab2868c6aa6 Added right aligment of parameteres blocks
etisserant
parents: 79
diff changeset
   176