Here the new files:
test1.py
CapturingOutputfromProcess.py
I think that the python script "test1.py" is started by my code, but self.process.ProcessState() say me quite another thing. I change the test1.py with a simple infinite print cycle:
#!/usr/bin/python
print "test1"
print "test2"
#from time import sleep
i=0
while 1:
print i
#sleep(1)
if i == 5:
#os.kill(os.getpid(),signal.SIGKILL)
pass
i +=1
#!/usr/bin/python
print "test1"
print "test2"
#from time import sleep
i=0
while 1:
print i
#sleep(1)
if i == 5:
#os.kill(os.getpid(),signal.SIGKILL)
pass
i +=1
To copy to clipboard, switch view to plain text mode
I think that the new process is started because i can see its pid on "System Monitor", and its cpu occupation. This is the new attemp in the script:
def startCommand(self):
self.
process.
start("python", QtCore.
QStringList(["/home/MyUserAccount/test1.py"])) StartString="Process started with pid: "+str(self.process.pid())
print StartString
self.textBrowser.append(StartString)
print self.process.ProcessState()
#self.process.close()
self.startButton.setEnabled(False)
self.stopButton.setEnabled(True)
#self.textBrowser.clear()
def processIsStarted(self):
print "according to SIGNAL STARTED() process with pid: ",self.process.pid()
def stopCommand(self):
print "Attempt to stop a process with Pid: ", str(self.process.pid())
print "What is the State of this process?"
print "Its State is ", self.process.ProcessState()
self.resetButtons()
print "Stop process, PID was: ", self.process.pid()
os.kill(self.process.pid(), signal.SIGKILL)
def startCommand(self):
self.process.start("python", QtCore.QStringList(["/home/MyUserAccount/test1.py"]))
StartString="Process started with pid: "+str(self.process.pid())
print StartString
self.textBrowser.append(StartString)
print self.process.ProcessState()
#self.process.close()
self.startButton.setEnabled(False)
self.stopButton.setEnabled(True)
#self.textBrowser.clear()
def processIsStarted(self):
print "according to SIGNAL STARTED() process with pid: ",self.process.pid()
def stopCommand(self):
print "Attempt to stop a process with Pid: ", str(self.process.pid())
print "What is the State of this process?"
print "Its State is ", self.process.ProcessState()
self.resetButtons()
print "Stop process, PID was: ", self.process.pid()
os.kill(self.process.pid(), signal.SIGKILL)
To copy to clipboard, switch view to plain text mode
When i run $python CapturingOutputfromProcess03.py , and press the button start, the message is shown correctly on the textbrowser "Process started with pid: 2277":
Process started with pid: 2277
0
according to SIGNAL STARTED() process with pid: 2277
Process started with pid: 2277
0
according to SIGNAL STARTED() process with pid: 2277
To copy to clipboard, switch view to plain text mode
A new pid appears on the System Monitor with its CPU occupation.
Then, when I press the stop button, the gui disappears and the terminal reveals this:
Attempt to stop a process with Pid: 2283
What is the State of this process?
Its State is 0
Stop process, PID was: 2283
Attempt to stop a process with Pid: 2283
What is the State of this process?
Its State is 0
Stop process, PID was: 2283
To copy to clipboard, switch view to plain text mode
I hope we can reach a solution.
Thanks a lot
Bookmarks