From cd0972ede87a2ef73bf37862257987c82006a962 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Fri, 10 Jul 2009 13:44:33 +0200 Subject: [PATCH] adding a new execnet example --HG-- branch : 1.0.x --- MANIFEST | 1 + example/execnet/redirect_remote_output.py | 31 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 example/execnet/redirect_remote_output.py diff --git a/MANIFEST b/MANIFEST index c6f2b9c3d..e9908800c 100644 --- 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 diff --git a/example/execnet/redirect_remote_output.py b/example/execnet/redirect_remote_output.py new file mode 100644 index 000000000..86f303f43 --- /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() +