techtonik / absub

Anti-blocking subprocess implementations https://bugs.python.org/issue14872

Home Page:https://stackoverflow.com/questions/34504970/non-blocking-read-on-os-pipe-on-windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

async_subprocess is a simple wrapper around Python's subprocess.Popen
class.  You use it just like you would use subprocess.Popen; there are only
two major differences:

    * You can only pass None or PIPE as values for stdout, stdin, stderr.
    * asyncomm() returns immediately with whatever data is available, rather
      than waiting for EOF and process termination.  As such, you can now call
      asyncomm() many times on the same object.

async_subprocess is beta software, so it might still be a bit buggy.  It has
been tested on the following configurations:

    * Linux (Fedora 15), Python 2.7.1
    * Linux (Fedora 15), Python 3.2
    * Windows Vista 32, Python 2.7.3

Example usage:

    from async_subprocess import AsyncPopen, PIPE
    args = ("echo", "Hello World!")
    proc = AsyncPopen(args, stdout=PIPE)
    stdoutdata, stderrdata = proc.asyncomm()
    print stdoutdata    # should print "Hello World!"

------------
 What's New 
------------
Version 0.5
* (techtonik) Implement standard communicate() using non-blocking layer.

Version 0.4
* (techtonik) Non-blocking communicate() is renamed to asyncomm() to allow
  making AsyncPopen() class a drop-in Popen() replacement that doesn't break
  existing codebase.

Version 0.3
* (techtonik) Change communicate() to return empty strings if pipes are
  alive and empty, and None if they are dead or closed.
* (techtonik) Wrap Popen.stdin to make sure that programs closing stdin
  directly do this in a threadsafe manner.

Version 0.2.3
* (techtonik) Fixed wrong lock being set in communicate() for stdout pipe.
* (techtonik) Added tests.

Version 0.2
* Got rid of the stray debug print statement that was accidentally left in
  version 0.1.  Sorry about that, it's gone now, and 0.2 has been checked for
  other stray debug statements.
* Support for Python 3 added.

About

Anti-blocking subprocess implementations https://bugs.python.org/issue14872

https://stackoverflow.com/questions/34504970/non-blocking-read-on-os-pipe-on-windows

License:Other


Languages

Language:Python 100.0%