Permalink
Browse files

Add documentation to execute_relay.py example

  • Loading branch information...
1 parent 28a4579 commit 8e2c83ded608d3c4212c3c5e3c2534d86186e360 @sporsh committed Nov 15, 2012
Showing with 15 additions and 3 deletions.
  1. +15 −3 examples/execute_relay.py
@@ -1,3 +1,13 @@
+"""Example that run local and remote process concurrently and relay output.
+
+A local process is started concurrently with a remote process.
+All output from the two processes are relayed to the parent process (the
+process executing this script).
+
+The sub-processes we start is the execution of a simple python script that
+print to stdout and stderr and exit with a exit code.
+"""
+
import sys
from getpass import getpass
from twisted.internet import reactor, defer
@@ -11,7 +21,8 @@
remote_user, remote_password = None, getpass()
-# Describe a command to run (a simple python script that prints to stdout and stderr)
+# Describe a command to run (a simple python script that prints to stdout
+# and stderr)
command = ["python", "-c", r"""
import sys
sys.stdout.write('standard output\n') # Write stdout data
@@ -22,12 +33,13 @@
class RelayProtocol(ProcessProtocol):
"""Trivial process protocol to relay stdout and stderr and report exit code
- from the child processes to our parent process (the process of this program).
+ from the child processes to our parent process (the process executing
+ this program).
"""
def __init__(self, data_precursor=''):
"""Set up the relay to map stdout and stderr to our parent process
- @param data_precursor: A precursor so we can tag where the data came from.
+ @param data_precursor: A precursor to tag where the data came from.
"""
self.outReceived = lambda data: sys.stdout.write(data_precursor+data)
self.errReceived = lambda data: sys.stderr.write(data_precursor+data)

0 comments on commit 8e2c83d

Please sign in to comment.