[py-svn] py-trunk commit 26abe92b6acf: adding a new execnet example

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Jul 14 21:37:59 CEST 2009


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1247226273 -7200
# Node ID 26abe92b6acf50222c8fcf0a2ed32c7c0655297d
# Parent 85ccddd0633f9583758e15a7daeaad34473313cd
adding a new execnet example

--- /dev/null
+++ b/example/execnet/redirect_remote_output.py
@@ -0,0 +1,31 @@
+"""
+redirect output from remote to a local function 
+showcasing features of the channel object:
+
+- sending a channel over a channel 
+- adapting a channel to a file object 
+- setting a callback for receiving channel data 
+
+"""
+
+import py
+
+gw = py.execnet.PopenGateway()
+
+outchan = gw.remote_exec("""
+    import sys
+    outchan = channel.gateway.newchannel()
+    sys.stdout = outchan.makefile("w")
+    channel.send(outchan) 
+""").receive()
+
+# note: callbacks execute in receiver thread! 
+def write(data):
+    print "received:", repr(data)
+outchan.setcallback(write)
+
+gw.remote_exec("""
+    print 'hello world'
+    print 'remote execution ends'
+""").waitclose()
+

--- a/MANIFEST
+++ b/MANIFEST
@@ -37,6 +37,7 @@ example/assertion/failure_demo.py
 example/assertion/test_failures.py
 example/assertion/test_setup_flow_example.py
 example/execnet/popen_read_multiple.py
+example/execnet/redirect_remote_output.py
 example/execnet/svn-sync-repo.py
 example/execnet/sysinfo.py
 example/funcarg/conftest.py



More information about the pytest-commit mailing list