--- a/Beremiz.py Sun Mar 18 23:50:51 2012 +0100
+++ b/Beremiz.py Wed Mar 28 21:08:31 2012 +0200
@@ -581,8 +581,9 @@
{False : "-x 0", True :"-x 1"}[taskbaricon],
self.local_runtime_tmpdir),
- self.local_runtime.spin(timeout=500, keyword = "working", kill_it = False)
+ timeout=500, keyword = "working") + self.local_runtime.spin() def KillLocalRuntime(self):
--- a/wxPopen.py Sun Mar 18 23:50:51 2012 +0100
+++ b/wxPopen.py Wed Mar 28 21:08:31 2012 +0200
@@ -26,18 +26,18 @@
import subprocess, ctypes
+from threading import Timer, Lock, Thread, Semaphore from signal import SIGTERM, SIGKILL
-class outputThread(threading.Thread):
+class outputThread(Thread): Thread is used to print the output of a command to the stdout
def __init__(self, Proc, fd, callback=None, endcallback=None):
- threading.Thread.__init__(self)
@@ -58,6 +58,7 @@
if self.callback : self.callback(outchunk)
while outchunk != '' and not self.killed :
outchunk = self.fd.readline()
+ if self.callback : self.callback(outchunk) @@ -67,7 +68,10 @@
self.endcallback(self.Proc.pid, err)
- def __init__(self, logger, Command, finish_callback=None, no_stdout=False, no_stderr=False, no_gui=True):
+ def __init__(self, logger, Command, finish_callback = None, + no_stdout = False, no_stderr = False, no_gui = True, + timeout = None, outlimit = None, errlimit = None, + endlog = None, keyword = None, kill_it = False): if not isinstance(Command, list):
self.Command_str = Command
@@ -89,10 +93,15 @@
+ self.errlimit = errlimit + self.outlimit = outlimit
+ self.finishsem = Semaphore(0) @@ -105,7 +114,7 @@
self.startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
popenargs["startupinfo"] = self.startupinfo
elif wx.Platform == '__WXGTK__':
- popenargs["shell"] = False #True
+ popenargs["shell"] = False self.Proc = subprocess.Popen( self.Command, **popenargs )
@@ -122,29 +131,35 @@
+ Timer(timeout,self.endlog).start()
+ if (self.keyword and v.find(self.keyword)!=-1) or (self.outlimit and self.outlen > self.outlimit):
self.logger.write_warning(v)
+ if self.errlimit and self.errlen > self.errlimit: def log_the_end(self,ecode,pid):
self.logger.write(self.Command_str + "\n")
self.logger.write_warning(_("exited with status %s (pid %s)\n")%(str(ecode),str(pid)))
def finish(self, pid,ecode):
self.log_the_end(ecode,pid)
if self.finish_callback is not None:
self.finish_callback(self,ecode,pid)
+ self.finishsem.release() def kill(self,gently=True):
@@ -166,26 +181,14 @@
- def spin(self, timeout=None, out_limit=None, err_limit=None, keyword = None, kill_it = True):
- while not self.finished:
- if err_limit and self.errlen > err_limit:
- if out_limit and self.outlen > out_limit:
- if keyword and self.outdata.find(keyword)!=-1:
+ if self.endlock.acquire(False): + self.finishsem.release() + if not self.outt.finished and self.kill_it: - if not self.outt.finished and kill_it:
+ self.finishsem.acquire() + return [self.exitcode, "".join(self.outdata), "".join(self.errdata)] - return [self.exitcode, self.outdata, self.errdata]