diff --git a/portal/__init__.py b/portal/__init__.py index 8ba781a..0f0667d 100644 --- a/portal/__init__.py +++ b/portal/__init__.py @@ -1,4 +1,4 @@ -__version__ = '3.2.0' +__version__ = '3.2.1' import multiprocessing as mp try: diff --git a/portal/server.py b/portal/server.py index 44e995a..ab87fb8 100644 --- a/portal/server.py +++ b/portal/server.py @@ -148,4 +148,7 @@ def _error(self, addr, reqnum, status, message): data = message.encode('utf-8') self.socket.send(addr, reqnum, status, data) if self.errors: + # Wait until the error is delivered to the client and then raise. + self.socket.shutdown() + self.socket.close() raise RuntimeError(message) diff --git a/portal/thread.py b/portal/thread.py index b5e9028..ee57880 100644 --- a/portal/thread.py +++ b/portal/thread.py @@ -21,7 +21,6 @@ class Thread: """ def __init__(self, fn, *args, name=None, start=False): - global TIDS self.fn = fn self.excode = None name = name or getattr(fn, '__name__', 'thread') diff --git a/tests/test_server.py b/tests/test_server.py index c4687eb..32be753 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -91,6 +91,27 @@ def test_unknown_method(self, Server): def test_server_errors(self, Server): port = portal.free_port() + server = Server(port, errors=False) + def fn(x): + if x == 2: + raise ValueError(x) + return x + server.bind('fn', fn) + server.start(block=False) + + client = portal.Client('localhost', port) + assert client.fn(1).result() == 1 + with pytest.raises(RuntimeError): + client.fn(2).result() + assert client.fn(3).result() == 3 + + client.close() + server.close() + + @pytest.mark.parametrize('Server', SERVERS) + def test_server_errors_raise(self, Server): + port = portal.free_port() + def server(port): server = Server(port, errors=True) def fn(x): @@ -108,8 +129,8 @@ def fn(x): client = portal.Client('localhost', port) assert client.fn(1).result() == 1 assert server.running - with pytest.raises(RuntimeError): - client.fn(2).result() + with pytest.raises((RuntimeError, TimeoutError)): + client.fn(2).result(timeout=3) client.close() server.join()