[py-svn] r10611 - in py/branch/py-collect/execnet: . testing
hpk at codespeak.net
hpk at codespeak.net
Thu Apr 14 13:13:55 CEST 2005
Author: hpk
Date: Thu Apr 14 13:13:55 2005
New Revision: 10611
Modified:
py/branch/py-collect/execnet/channel.py
py/branch/py-collect/execnet/gateway.py
py/branch/py-collect/execnet/testing/test_gateway.py
Log:
simplify and flexibilize the basic execnet API.
you can now do:
channel = gateway.newchannel()
channel.remote_exec("...")
in which case the channel will be used as the local connection
point to the remotely executing source.
You can now switch channel modes by providing a callback:
l = []
channel = gateway.newchannel()
channel.setcallback(l.append)
channel.remote_exec("channel.send(42)")
where 'l' will end up having the value 42.
the gateway.remote_exec() is now merely a shortcut
for creating a channel and calling it's remote_exec
and returning the channel.
Modified: py/branch/py-collect/execnet/channel.py
==============================================================================
--- py/branch/py-collect/execnet/channel.py (original)
+++ py/branch/py-collect/execnet/channel.py Thu Apr 14 13:13:55 2005
@@ -43,6 +43,9 @@
put(Message.CHANNEL_CLOSE(self.id))
self._close()
+ def remote_exec(self, source):
+ self.gateway._remote_exec(self, source)
+
def _close(self, finalitem=EOFError()):
if self.id in self.gateway.channelfactory:
del self.gateway.channelfactory[self.id]
Modified: py/branch/py-collect/execnet/gateway.py
==============================================================================
--- py/branch/py-collect/execnet/gateway.py (original)
+++ py/branch/py-collect/execnet/gateway.py Thu Apr 14 13:13:55 2005
@@ -277,16 +277,7 @@
# where we get called from
callback(data)
- # _____________________________________________________________________
- #
- # High Level Interface
- # _____________________________________________________________________
-
- def remote_exec(self, source, callback=None):
- """ return channel object for communicating with the asynchronously
- executing 'source' code which will have a corresponding 'channel'
- object in its executing namespace.
- """
+ def _remote_exec(self, channel, source):
try:
source = str(Source(source))
except NameError:
@@ -295,10 +286,28 @@
source = str(py.code.Source(source))
except ImportError:
pass
- channel = self.channelfactory.new()
- channel.setcallback(callback)
self._outgoing.put(Message.CHANNEL_OPEN(channel.id, source))
- return channel
+
+ # _____________________________________________________________________
+ #
+ # High Level Interface
+ # _____________________________________________________________________
+ #
+ def newchannel(self):
+ """ return new channel object. """
+ return self.channelfactory.new()
+
+ def remote_exec(self, source):
+ """ return channel object for communicating with the asynchronously
+ executing 'source' code which will have a corresponding 'channel'
+ object in its executing namespace. If a channel object is not
+ provided a new channel will be created. If a channel is provided
+ is will be returned as well.
+ """
+ channel = self.newchannel()
+ channel.remote_exec(source)
+ return channel
+
def remote_redirect(self, stdout):
""" return a handle representing a redirection of of remote
@@ -330,6 +339,9 @@
self.close()
def close(self, timeout=1.0):
+ """ close redirection on remote side and wait
+ for closing.
+ """
self.gateway.remote_exec("""
import sys
channel = sys.stdout.channel
Modified: py/branch/py-collect/execnet/testing/test_gateway.py
==============================================================================
--- py/branch/py-collect/execnet/testing/test_gateway.py (original)
+++ py/branch/py-collect/execnet/testing/test_gateway.py Thu Apr 14 13:13:55 2005
@@ -132,12 +132,14 @@
newchan.waitclose(0.3)
def test_channel_receiver_callback(self):
+ channel = self.gw.newchannel()
l = []
- channel = self.gw.remote_exec('''
+ channel.setcallback(l.append)
+ channel.remote_exec('''
channel.send(42)
channel.send(13)
- ''', callback=l.append)
- channel.waitclose(1.0)
+ ''')
+ channel.waitclose(1.0)
assert l == [42,13]
def test_channel_receiver_callback_callback_then_not(self):
More information about the pytest-commit
mailing list