X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=subproc.py;h=57a95682803fcd83bd00d554c8d55784af3cef15;hb=3e29cb1a49f602f4a647c18ae64f0516a76de236;hp=fcb7e1e222715bbea0408062dd73da92b5a13692;hpb=f61e98fb060b1702bc02a2dddbe8dd49443ec0b6;p=bookmarks_db.git diff --git a/subproc.py b/subproc.py old mode 100644 new mode 100755 index fcb7e1e..57a9568 --- a/subproc.py +++ b/subproc.py @@ -1,3 +1,5 @@ +#! /usr/bin/env python + """Run a subprocess and communicate with it via stdin, stdout, and stderr. Requires that platform supports, eg, posix-style 'os.pipe' and 'os.fork' @@ -141,7 +143,9 @@ class Subprocess: except os.error as error: errno, msg = error if errno == 10: + self.pid = None raise SubprocessError("Subprocess '%s' failed." % self.cmd) + self.pid = None raise SubprocessError("Subprocess failed[%d]: %s" % (errno, msg)) if pid == self.pid: # child exited already @@ -153,6 +157,7 @@ class Subprocess: "child killed by signal %d with a return code of %d" % (sig, rc)) if rc: + self.pid = None raise SubprocessError( "child exited with return code %d" % rc) # Child may have exited, but not in error, so we won't say @@ -648,15 +653,15 @@ class Ph: ############################################################################# def test(p=0): - print("\tOpening subprocess:") - p = Subprocess('cat', 1) # set to expire noisily... - print(p) print("\tOpening bogus subprocess, should fail:") try: b = Subprocess('/', 1) print("\tOops! Null-named subprocess startup *succeeded*?!?") except SubprocessError: print("\t...yep, it failed.") + print("\tOpening cat subprocess:") + p = Subprocess('cat', 1) # set to expire noisily... + print(p) print('\tWrite, then read, two newline-teriminated lines, using readline:') p.write('first full line written\n'); p.write('second.\n') print(repr(p.readline())) @@ -686,3 +691,6 @@ def test(p=0): del p print("\tDone.") return None + +if __name__ == '__main__': + test()