[pypy-svn] r78712 - in pypy/branch/fast-forward/pypy: . module/_multiprocessing module/_multiprocessing/test
afa at codespeak.net
afa at codespeak.net
Fri Nov 5 01:16:50 CET 2010
Author: afa
Date: Fri Nov 5 01:16:47 2010
New Revision: 78712
Modified:
pypy/branch/fast-forward/pypy/conftest.py
pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_connection.py
pypy/branch/fast-forward/pypy/module/_multiprocessing/test/test_connection.py
Log:
Hard work to let the tests pass with -A.
os.dup() could have been a solution, except that
it does not work on Windows sockets...
Modified: pypy/branch/fast-forward/pypy/conftest.py
==============================================================================
--- pypy/branch/fast-forward/pypy/conftest.py (original)
+++ pypy/branch/fast-forward/pypy/conftest.py Fri Nov 5 01:16:47 2010
@@ -181,6 +181,9 @@
def getbuiltinmodule(self, name):
return __import__(name)
+ def delslice(self, obj, *args):
+ obj.__delslice__(*args)
+
def translation_test_so_skip_if_appdirect():
if option.runappdirect:
py.test.skip("translation test, skipped for appdirect")
Modified: pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_connection.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_connection.py (original)
+++ pypy/branch/fast-forward/pypy/module/_multiprocessing/interp_connection.py Fri Nov 5 01:16:47 2010
@@ -211,9 +211,7 @@
raise WindowsError(geterrno(), "recv")
return buf.str(length)
def CLOSE(self):
- from pypy.rlib._rsocket_rffi import socketclose, geterrno
- if socketclose(self.fd) < 0:
- raise WindowsError(geterrno(), "close")
+ socketclose(self.fd)
else:
def WRITE(self, data):
import os
@@ -223,7 +221,10 @@
return os.read(self.fd, length)
def CLOSE(self):
import os
- os.close(self.fd)
+ try:
+ os.close(self.fd)
+ except OSError:
+ pass
def __init__(self, fd, flags):
W_BaseConnection.__init__(self, flags)
Modified: pypy/branch/fast-forward/pypy/module/_multiprocessing/test/test_connection.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_multiprocessing/test/test_connection.py (original)
+++ pypy/branch/fast-forward/pypy/module/_multiprocessing/test/test_connection.py Fri Nov 5 01:16:47 2010
@@ -1,7 +1,7 @@
import py
import sys
from pypy.conftest import gettestobjspace, option
-from pypy.interpreter.gateway import interp2app
+from pypy.interpreter.gateway import interp2app, W_Root
class TestImport:
def test_simple(self):
@@ -93,6 +93,7 @@
def setup_class(cls):
space = gettestobjspace(usemodules=('_multiprocessing', 'thread'))
cls.space = space
+ cls.w_connections = space.newlist([])
def socketpair(space):
"A socket.socketpair() that works on Windows"
@@ -110,25 +111,43 @@
server, addr = serverSocket.accept()
# keep sockets alive during the test
- cls.connections = server, client
+ space.call_method(cls.w_connections, "append", space.wrap(server))
+ space.call_method(cls.w_connections, "append", space.wrap(client))
return space.wrap((server.fileno(), client.fileno()))
- w_socketpair = space.wrap(interp2app(socketpair))
+ if option.runappdirect:
+ w_socketpair = lambda: socketpair(space)
+ else:
+ w_socketpair = space.wrap(interp2app(socketpair))
cls.w_make_pair = space.appexec(
- [w_socketpair], """(socketpair):
+ [w_socketpair, cls.w_connections], """(socketpair, connections):
import _multiprocessing
import os
def make_pair():
fd1, fd2 = socketpair()
rhandle = _multiprocessing.Connection(fd1, writable=False)
whandle = _multiprocessing.Connection(fd2, readable=False)
+ connections.append(rhandle)
+ connections.append(whandle)
return rhandle, whandle
return make_pair
""")
- def teardown_class(cls):
+
+ def teardown_method(self, func):
+ # Work hard to close all sockets and connections now!
+ # since the fd is probably already closed, another unrelated
+ # part of the program will probably reuse it;
+ # And any object forgotten here will close it on destruction...
try:
- del cls.connections
+ w_connections = self.w_connections
except AttributeError:
- pass
+ return
+ space = self.space
+ for c in space.unpackiterable(w_connections):
+ if isinstance(c, W_Root):
+ space.call_method(c, "close")
+ else:
+ c.close()
+ space.delslice(w_connections, space.wrap(0), space.wrap(100))
More information about the Pypy-commit
mailing list