[py-svn] r6916 - in py/dist: doc py py/execnet py/execnet/bin py/test py/test/test/data
hpk at codespeak.net
hpk at codespeak.net
Wed Oct 13 17:58:29 CEST 2004
Author: hpk
Date: Wed Oct 13 17:58:28 2004
New Revision: 6916
Modified:
py/dist/doc/execnet.txt
py/dist/py/api_test.py
py/dist/py/execnet/bin/startserver.py
py/dist/py/execnet/gateway.py
py/dist/py/execnet/gateway_test.py
py/dist/py/execnet/register.py
py/dist/py/execnet/source_test.py
py/dist/py/test/collect.py
py/dist/py/test/collect_test.py
py/dist/py/test/test/data/Collector.py
Log:
- fixes for python2.2
- removed timeout parameter from many execnet methods
- introduced documentation for upcoming Channel improvements
(reraising remote exceptions)
Modified: py/dist/doc/execnet.txt
==============================================================================
--- py/dist/doc/execnet.txt (original)
+++ py/dist/doc/execnet.txt Wed Oct 13 17:58:28 2004
@@ -80,6 +80,16 @@
channel.receive():
receives an item that was sent from the other side,
possibly blocking if there is none.
+ Note that exceptions from the other side will be
+ reraised as gateway.ExecutionFailed exceptions containing
+ a textual representation of the remote traceback.
+
+ channel.waitclose(timeout=None):
+ wait until this channel is closed. Note that a closed
+ channel may still hold items that will be received or
+ send. Note that exceptions from the other side will be
+ reraised as gateway.ExecutionFailed exceptions containing
+ a textual representation of the remote traceback.
#
# API for setting and getting named values ("named signals")
Modified: py/dist/py/api_test.py
==============================================================================
--- py/dist/py/api_test.py (original)
+++ py/dist/py/api_test.py Wed Oct 13 17:58:28 2004
@@ -1,6 +1,7 @@
from py.test import raises
import py
+import sys
import inspect
class API_V0_namespace_consistence:
@@ -43,7 +44,8 @@
obj = getattr(mod, name)
fullpath = modpath + '.' + name
assert obj.__module__ == modpath
- assert obj.__name__ == name
+ if sys.version_info >= (2,3):
+ assert obj.__name__ == name
def assert_function(modpath, name):
mod = __import__(modpath, None, None, [name])
Modified: py/dist/py/execnet/bin/startserver.py
==============================================================================
--- py/dist/py/execnet/bin/startserver.py (original)
+++ py/dist/py/execnet/bin/startserver.py Wed Oct 13 17:58:28 2004
@@ -7,7 +7,7 @@
#
progname = 'socket_readline_exec_server-1.2'
-debug = 1
+debug = 0
import sys, socket, os
@@ -19,7 +19,7 @@
def execloop(serversock):
while 1:
try:
- print progname, 'Entering Accept loop', sock.getsockname()
+ print progname, 'Entering Accept loop', serversock.getsockname()
clientsock,address = serversock.accept()
print progname, 'got new connection from %s %s' % address
clientfile = clientsock.makefile('r+b',0)
Modified: py/dist/py/execnet/gateway.py
==============================================================================
--- py/dist/py/execnet/gateway.py (original)
+++ py/dist/py/execnet/gateway.py Wed Oct 13 17:58:28 2004
@@ -1,7 +1,7 @@
import sys, os, threading, struct, Queue, traceback
import atexit
-import time
+# XXX the following line should not be here
from py.__impl__.execnet.source import Source
debug = 0
@@ -19,13 +19,11 @@
threading.Thread(target=self.thread_receiver, name='receiver'),
threading.Thread(target=self.thread_sender, name='sender'),
]
- for x in self.iothreads:
- x.start()
self.workerthreads = w = []
for x in range(self.num_worker_threads):
w.append(threading.Thread(target=self.thread_executor,
name='executor %d' % x))
- for x in w:
+ for x in self.iothreads + w:
x.start()
if not _gateways:
atexit.register(cleanup_atexit)
@@ -118,7 +116,7 @@
loc = { 'channel' : channel }
self.trace("execution starts:", repr(source)[:50])
try:
- co = compile(source, '', 'exec')
+ co = compile(source+'\n', '', 'exec')
exec co in loc
finally:
self.trace("execution finished:", repr(source)[:50])
@@ -146,20 +144,17 @@
object in turn.
"""
source = str(Source(source))
- if debug:
- import parser
- parser.suite(source)
channel = self.channelfactory.new()
self._outgoing.put(Message.CHANNEL_OPEN(channel.id, source))
return channel
- def remote_exec_sync(self, source, timeout=10):
+ def remote_exec_sync(self, source):
""" synchronously execute source on the other side of the gateway
return after execution of the source finishes on the other
side.
"""
channel = self.remote_exec_async(source)
- channel.waitclose(timeout=timeout)
+ channel.waitclose()
return
class Channel(object):
@@ -178,9 +173,14 @@
flag = self._closeevent.isSet() and "closed" or "open"
return "<Channel id=%d %s>" % (self.id, flag)
- def waitclose(self, timeout=None):
- """ return error message (None if no error) after waiting for close event. """
- self._closeevent.wait(timeout)
+ def waitclose(self, timeout):
+ """ wait until this channel is closed. Note that a closed
+ channel may still hold items that will be received or
+ send. Note that exceptions from the other side will be
+ reraised as gateway.ExecutionFailed exceptions containing
+ a textual representation of the remote traceback.
+ """
+ self._closeevent.wait(timeout=timeout)
if not self._closeevent.isSet():
raise IOError, "Timeout"
return self._error
@@ -193,10 +193,14 @@
eval(repr(V)) == V."""
self.gateway._outgoing.put(Message.CHANNEL_DATA(self.id, repr(item)))
- def receive(self, timeout=None):
+ def receive(self):
"""receives an item that was sent from the other side,
- possibly blocking if there is none."""
- return self._items.get(timeout=timeout)
+ possibly blocking if there is none.
+ Note that exceptions from the other side will be
+ reraised as gateway.ExecutionFailed exceptions containing
+ a textual representation of the remote traceback.
+ """
+ return self._items.get()
#
# helpers
Modified: py/dist/py/execnet/gateway_test.py
==============================================================================
--- py/dist/py/execnet/gateway_test.py (original)
+++ py/dist/py/execnet/gateway_test.py Wed Oct 13 17:58:28 2004
@@ -76,14 +76,6 @@
def test_correct_setup(self):
assert self.gw.workerthreads and self.gw.iothreads
- def test_syntax_error_in_debug_mode(self):
- debug = gateway.debug
- try:
- gateway.debug = 1
- py.test.raises(SyntaxError, self.gw.remote_exec_async, "a='")
- finally:
- gateway.debug = debug
-
def test_remote_exec_async_waitclose(self):
channel = self.gw.remote_exec_async('pass')
channel.waitclose(timeout=3.0)
@@ -94,7 +86,7 @@
channel.send(obj)
''')
channel.send(42)
- result = channel.receive(timeout=3.0)
+ result = channel.receive()
assert result == 42
class TestBasicPopenGateway(PopenGatewayTestSetup, BasicRemoteExecution):
@@ -135,6 +127,9 @@
try:
sock = bind_and_listen(("localhost", i))
except socket.error:
+ print "got error"
+ import traceback
+ traceback.print_exc()
continue
else:
channel.send(i)
Modified: py/dist/py/execnet/register.py
==============================================================================
--- py/dist/py/execnet/register.py (original)
+++ py/dist/py/execnet/register.py Wed Oct 13 17:58:28 2004
@@ -1,8 +1,7 @@
from py.magic import autopath ; autopath = autopath()
-import Queue
-
import os, inspect, socket
+import sys
import py
from py.__impl__.execnet import inputoutput, gateway
@@ -27,14 +26,13 @@
inspect.getsource(gateway),
io.server_stmt,
"Gateway(io=io, startcount=2).join()",
- "print 'exiting gateway'",
]
source = "\n".join(bootstrap)
self.trace("sending gateway bootstrap code")
io.write('%r\n' % source)
class PopenGateway(InstallableGateway):
- def __init__(self, python="python"):
+ def __init__(self, python=sys.executable):
cmd = '%s -u -c "exec input()"' % python
infile, outfile = os.popen2(cmd)
io = inputoutput.Popen2IO(infile, outfile)
@@ -44,8 +42,9 @@
def exit(self):
super(PopenGateway, self).exit()
try:
- pid = self._pidchannel.receive(0.5)
- except Queue.Empty():
+ self._pidchannel.waitclose(timeout=0.5)
+ pid = self._pidchannel.receive()
+ except IOError:
self.trace("could not receive child PID")
else:
self.trace("waiting for pid %s" % pid)
Modified: py/dist/py/execnet/source_test.py
==============================================================================
--- py/dist/py/execnet/source_test.py (original)
+++ py/dist/py/execnet/source_test.py Wed Oct 13 17:58:28 2004
@@ -38,4 +38,3 @@
#x.indent("try:",
# """except:
-
Modified: py/dist/py/test/collect.py
==============================================================================
--- py/dist/py/test/collect.py (original)
+++ py/dist/py/test/collect.py Wed Oct 13 17:58:28 2004
@@ -34,7 +34,7 @@
def _except(self):
excinfo = sys.exc_info()
- if issubclass(excinfo[0], (KeyboardInterrupt, SystemExit)):
+ if isinstance(excinfo[1], (KeyboardInterrupt, SystemExit)):
raise excinfo # KeyboardInterrupt
return Error(excinfo)
Modified: py/dist/py/test/collect_test.py
==============================================================================
--- py/dist/py/test/collect_test.py (original)
+++ py/dist/py/test/collect_test.py Wed Oct 13 17:58:28 2004
@@ -31,7 +31,7 @@
assert isinstance(l[0], test.collect.Error)
import traceback
print traceback.print_exception(*l[0].excinfo)
- assert issubclass(l[0].excinfo[0], (IOError, OSError))
+ assert isinstance(l[0].excinfo[1], (IOError, OSError))
def test_syntax_error_in_module():
modpath = 'py.__impl__.utest.test.data.syntax_error.whatever'
Modified: py/dist/py/test/test/data/Collector.py
==============================================================================
--- py/dist/py/test/test/data/Collector.py (original)
+++ py/dist/py/test/test/data/Collector.py Wed Oct 13 17:58:28 2004
@@ -1,4 +1,4 @@
-
+from __future__ import generators
from py.test import collect
class Collector(collect.PyCollector):
More information about the pytest-commit
mailing list