[Tutor] How to Terminate a Popen call?
SM
sunithanc at gmail.com
Wed Oct 23 13:13:55 CEST 2013
Hello eryksun,
Thanks, very much, for the very quick and helpful reply. It fixed my
problem.
-Sm
On Tue, Oct 22, 2013 at 10:33 PM, eryksun <eryksun at gmail.com> wrote:
> 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131023/e90205dd/attachment.html>
More information about the Tutor
mailing list