Commits

anatoly techtonik committed a5891ff

Rename our custom communicate() to asyncomm(), so that AsyncPopen()
could be a drop-in Popen() replacement.

Comments (0)

Files changed (3)

 two major differences:
 
     * You can only pass None or PIPE as values for stdout, stdin, stderr.
-    * communicate() returns immediately with whatever data is available, rather
+    * asyncomm() returns immediately with whatever data is available, rather
       than waiting for EOF and process termination.  As such, you can now call
-      communicate() many times on the same object.
+      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:
     from async_subprocess import AsyncPopen, PIPE
     args = ("echo", "Hello World!")
     proc = AsyncPopen(args, stdout=PIPE)
-    stdoutdata, stderrdata = proc.communicate()
+    stdoutdata, stderrdata = proc.asyncomm()
     print stdoutdata    # should print "Hello World!"
 
 ------------
  What's New 
 ------------
+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.

async_subprocess.py

       IOError: close() called during concurrent operation on the same file object.
 '''
 
-__version__ = '0.3'
+__version__ = '0.4'
 
 from subprocess import PIPE, Popen
 from threading  import Thread, Lock
     
     Do not directly access AsyncPopen.stdout, AsyncPopen.stderr, or
     AsyncPopen.stdin.  Instead, use the (non-blocking asynchronous)
-    AsyncPopen.communicate() method.
+    AsyncPopen.asyncomm() method.
     
     This reads entire lines from stdout and stderr at once.
     
         if self._stdin:
             self.stdin = StdinQueue(self.stdin)
     
-    def communicate(self, input=None):
+    def asyncomm(self, input=None):
         '''
         Interact with process: Enqueue data to be sent to stdin.  Return data
         read from stdout and stderr as a tuple (stdoutdata, stderrdata).  Do

tests/pollread.py

 while p.poll() is None:
   time.sleep(0.001) # sleep to avoid 100% CPU load
   counter += 1
-  out, err = p.communicate()
+  out, err = p.asyncomm()
   if out:
     print("Got '%s' on %dth iteration." % (out.strip(), counter))
 
 
 # Missing tests:
 # [ ] p = AsyncPopen(cmd)
-#   [ ] communicate() with dead pipes returns (None, None)
+#   [ ] asyncomm() with dead pipes returns (None, None)
 # [ ] p = AsyncPopen(cmd, stdout=PIPE)
-#   [ ] communicate() with one dead pipe returns str, None
-#   [ ] communicate() with Python 3 returns ???, None
-#   [ ] communicate() with empty pipe returns '', None
-#   [ ] communicate() with closed pipe returns None, None
-#     [ ] figure out when communicate() can be called wuth closed pipe
+#   [ ] asyncomm() with one dead pipe returns str, None
+#   [ ] asyncomm() with Python 3 returns ???, None
+#   [ ] asyncomm() with empty pipe returns '', None
+#   [ ] asyncomm() with closed pipe returns None, None
+#     [ ] figure out when asyncomm() can be called wuth closed pipe
 # [ ] p = AsyncPopen(cmd, stdin=PIPE)
 #   [ ] try to guide some process
 # [ ] p = AsyncPopen(cmd, stdout=PIPE, stderr=PIPE)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.