X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=subproc.py;h=502d5dd19190d6456128d89e40434386ea987713;hb=34b8d0278505311f33805a54bc758bc4b690c882;hp=1828b1c240151e1df7d8a3d8d809e912f6820c6f;hpb=a7daaf8f136d162109a5541a98f44991855628cc;p=bookmarks_db.git diff --git a/subproc.py b/subproc.py old mode 100644 new mode 100755 index 1828b1c..502d5dd --- 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' @@ -49,7 +51,9 @@ import select import signal -SubprocessError = 'SubprocessError' +class SubprocessError(Exception): + pass + # You may need to increase execvp_grace_seconds, if you have a large or slow # path to search: execvp_grace_seconds = 0.5 @@ -646,15 +650,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())) @@ -684,3 +688,6 @@ def test(p=0): del p print("\tDone.") return None + +if __name__ == '__main__': + test()