easybuild.tools.asyncprocess module

Module to allow Asynchronous subprocess use on Windows and Posix platforms

The ‘subprocess’ module in Python 2.4 has made creating and accessing subprocess streams in Python relatively convenient for all supported platforms, but what if you want to interact with the started subprocess? That is, what if you want to send a command, read the response, and send a new command based on that response?

Now there is a solution. The included subprocess.Popen subclass adds three new commonly used methods:

recv(maxsize=None) recv_err(maxsize=None) and send(input)
along with a utility method:
send_recv(input=’‘, maxsize=None).

recv() and recv_err() both read at most maxsize bytes from the started subprocess. send() sends strings to the started subprocess. send_recv() will send the provided input, and read up to maxsize bytes from both stdout and stderr.

If any of the pipes are closed, the attributes for those pipes will be set to None, and the methods will return None.

  • downloaded 05/08/2010
  • modified

– added STDOUT handle

author:Josiah Carlson
author:Stijn De Weirdt (Ghent University)
author:Dries Verdegem (Ghent University)
author:Kenneth Hoste (Ghent University)
author:Pieter De Baets (Ghent University)
author:Jens Timmerman (Ghent University)
class easybuild.tools.asyncprocess.Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0)

Bases: subprocess.Popen

get_conn_maxsize(which, maxsize)
send_recv(inp='', maxsize=None)
easybuild.tools.asyncprocess.recv_some(p, t=0.2, e=1, tr=5, stderr=0)
easybuild.tools.asyncprocess.send_all(p, data)