equal
deleted
inserted
replaced
51 while self.retval is None and not self.killed : |
51 while self.retval is None and not self.killed : |
52 if self.endcallback: |
52 if self.endcallback: |
53 self.retval = self.Proc.poll() |
53 self.retval = self.Proc.poll() |
54 else: |
54 else: |
55 self.retval = self.Proc.returncode |
55 self.retval = self.Proc.returncode |
56 |
56 |
57 outchunk = self.fd.readline() |
57 outchunk = self.fd.readline() |
58 if self.callback : self.callback(outchunk) |
58 if self.callback : self.callback(outchunk) |
59 while outchunk != '' and not self.killed : |
59 while outchunk != '' and not self.killed : |
60 outchunk = self.fd.readline() |
60 outchunk = self.fd.readline() |
61 if self.callback : self.callback(outchunk) |
61 if self.callback : self.callback(outchunk) |
106 self.exitcode = None |
106 self.exitcode = None |
107 self.outdata = [] |
107 self.outdata = [] |
108 self.errdata = [] |
108 self.errdata = [] |
109 self.keyword = keyword |
109 self.keyword = keyword |
110 self.kill_it = kill_it |
110 self.kill_it = kill_it |
111 self.startsem = Semaphore(0) |
111 self.startsem = Semaphore(0) |
112 self.finishsem = Semaphore(0) |
112 self.finishsem = Semaphore(0) |
113 self.endlock = Lock() |
113 self.endlock = Lock() |
114 |
114 |
115 popenargs= { |
115 popenargs= { |
116 "cwd":os.getcwd() if cwd is None else cwd, |
116 "cwd":os.getcwd() if cwd is None else cwd, |
128 if timeout: |
128 if timeout: |
129 self.timeout = Timer(timeout,self.endlog) |
129 self.timeout = Timer(timeout,self.endlog) |
130 self.timeout.start() |
130 self.timeout.start() |
131 else: |
131 else: |
132 self.timeout = None |
132 self.timeout = None |
133 |
133 |
134 self.Proc = subprocess.Popen( self.Command, **popenargs ) |
134 self.Proc = subprocess.Popen( self.Command, **popenargs ) |
135 |
135 |
136 self.outt = outputThread( |
136 self.outt = outputThread( |
137 self.Proc, |
137 self.Proc, |
138 self.Proc.stdout, |
138 self.Proc.stdout, |
167 def log_the_end(self,ecode,pid): |
167 def log_the_end(self,ecode,pid): |
168 self.logger.write(self.Command_str + "\n") |
168 self.logger.write(self.Command_str + "\n") |
169 self.logger.write_warning(_("exited with status {a1} (pid {a2})\n").format(a1 = str(ecode), a2 = str(pid))) |
169 self.logger.write_warning(_("exited with status {a1} (pid {a2})\n").format(a1 = str(ecode), a2 = str(pid))) |
170 |
170 |
171 def finish(self, pid,ecode): |
171 def finish(self, pid,ecode): |
172 # avoid running function before start is finished |
172 # avoid running function before start is finished |
173 self.startsem.acquire() |
173 self.startsem.acquire() |
174 if self.timeout: |
174 if self.timeout: |
175 self.timeout.cancel() |
175 self.timeout.cancel() |
176 self.exitcode = ecode |
176 self.exitcode = ecode |
177 if self.exitcode != 0: |
177 if self.exitcode != 0: |
183 |
183 |
184 def kill(self,gently=True): |
184 def kill(self,gently=True): |
185 # avoid running kill before start is finished |
185 # avoid running kill before start is finished |
186 self.startsem.acquire() |
186 self.startsem.acquire() |
187 self.startsem.release() |
187 self.startsem.release() |
188 |
188 |
189 self.outt.killed = True |
189 self.outt.killed = True |
190 self.errt.killed = True |
190 self.errt.killed = True |
191 if wx.Platform == '__WXMSW__': |
191 if wx.Platform == '__WXMSW__': |
192 PROCESS_TERMINATE = 1 |
192 PROCESS_TERMINATE = 1 |
193 handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.Proc.pid) |
193 handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, self.Proc.pid) |
213 |
213 |
214 |
214 |
215 def spin(self): |
215 def spin(self): |
216 self.finishsem.acquire() |
216 self.finishsem.acquire() |
217 return [self.exitcode, "".join(self.outdata), "".join(self.errdata)] |
217 return [self.exitcode, "".join(self.outdata), "".join(self.errdata)] |
218 |
|