[Tutor] How to Terminate a Popen call?
eryksun
eryksun at gmail.com
Wed Oct 23 04:33:56 CEST 2013
On Tue, Oct 22, 2013 at 9:04 PM, SM <sunithanc at gmail.com> wrote:
> def run(self):
> (process, err) = Popen(self.fwcmd, stdout=PIPE,
> stderr=PIPE).communicate()
> if len(err) > 0:
> # print("Error")
> # Error handling code
> else:
> # print("Success")
Store the Popen() instance before calling its communicate() method:
p = self.process = Popen(self.fwcmd, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
if p.returncode:
raise CalledProcessError(p.returncode, self.fwcmd, (out, err))
communicate() sets returncode; an error is indicated by a non-zero
value. Some programs write non-error information to stderr, so use the
return code to detect an error.
More information about the Tutor
mailing list