portal 3.1.8__tar.gz → 3.1.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {portal-3.1.8/portal.egg-info → portal-3.1.10}/PKG-INFO +1 -1
  2. {portal-3.1.8 → portal-3.1.10}/portal/__init__.py +1 -1
  3. {portal-3.1.8 → portal-3.1.10}/portal/contextlib.py +9 -8
  4. {portal-3.1.8 → portal-3.1.10}/portal/server_socket.py +9 -4
  5. {portal-3.1.8 → portal-3.1.10/portal.egg-info}/PKG-INFO +1 -1
  6. {portal-3.1.8 → portal-3.1.10}/tests/test_batching.py +2 -1
  7. {portal-3.1.8 → portal-3.1.10}/tests/test_errfile.py +10 -11
  8. {portal-3.1.8 → portal-3.1.10}/LICENSE +0 -0
  9. {portal-3.1.8 → portal-3.1.10}/MANIFEST.in +0 -0
  10. {portal-3.1.8 → portal-3.1.10}/README.md +0 -0
  11. {portal-3.1.8 → portal-3.1.10}/portal/batching.py +0 -0
  12. {portal-3.1.8 → portal-3.1.10}/portal/buffers.py +0 -0
  13. {portal-3.1.8 → portal-3.1.10}/portal/client.py +0 -0
  14. {portal-3.1.8 → portal-3.1.10}/portal/client_socket.py +0 -0
  15. {portal-3.1.8 → portal-3.1.10}/portal/packlib.py +0 -0
  16. {portal-3.1.8 → portal-3.1.10}/portal/poollib.py +0 -0
  17. {portal-3.1.8 → portal-3.1.10}/portal/process.py +0 -0
  18. {portal-3.1.8 → portal-3.1.10}/portal/server.py +0 -0
  19. {portal-3.1.8 → portal-3.1.10}/portal/sharray.py +0 -0
  20. {portal-3.1.8 → portal-3.1.10}/portal/thread.py +0 -0
  21. {portal-3.1.8 → portal-3.1.10}/portal/utils.py +0 -0
  22. {portal-3.1.8 → portal-3.1.10}/portal.egg-info/SOURCES.txt +0 -0
  23. {portal-3.1.8 → portal-3.1.10}/portal.egg-info/dependency_links.txt +0 -0
  24. {portal-3.1.8 → portal-3.1.10}/portal.egg-info/requires.txt +0 -0
  25. {portal-3.1.8 → portal-3.1.10}/portal.egg-info/top_level.txt +0 -0
  26. {portal-3.1.8 → portal-3.1.10}/pyproject.toml +0 -0
  27. {portal-3.1.8 → portal-3.1.10}/requirements.txt +0 -0
  28. {portal-3.1.8 → portal-3.1.10}/setup.cfg +0 -0
  29. {portal-3.1.8 → portal-3.1.10}/setup.py +0 -0
  30. {portal-3.1.8 → portal-3.1.10}/tests/test_client.py +0 -0
  31. {portal-3.1.8 → portal-3.1.10}/tests/test_pack.py +0 -0
  32. {portal-3.1.8 → portal-3.1.10}/tests/test_process.py +0 -0
  33. {portal-3.1.8 → portal-3.1.10}/tests/test_server.py +0 -0
  34. {portal-3.1.8 → portal-3.1.10}/tests/test_socket.py +0 -0
  35. {portal-3.1.8 → portal-3.1.10}/tests/test_thread.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: portal
3
- Version: 3.1.8
3
+ Version: 3.1.10
4
4
  Summary: Fast and reliable distributed systems in Python
5
5
  Home-page: http://github.com/danijar/portal
6
6
  Author: Danijar Hafner
@@ -1,4 +1,4 @@
1
- __version__ = '3.1.8'
1
+ __version__ = '3.1.10'
2
2
 
3
3
  import multiprocessing as mp
4
4
  try:
@@ -60,6 +60,7 @@ class Context:
60
60
  errfile = pathlib.Path(errfile)
61
61
  assert hasattr(errfile, 'exists') and hasattr(errfile, 'write_text')
62
62
  self.errfile = errfile
63
+ self._check_errfile()
63
64
 
64
65
  if interval:
65
66
  assert isinstance(interval, (int, float))
@@ -144,14 +145,14 @@ class Context:
144
145
  return self.children[ident]
145
146
 
146
147
  def _watcher(self):
147
- while True:
148
- if self.errfile and self.errfile.exists():
149
- message = f'Shutting down due to error file: {self.errfile}',
150
- print(message, file=sys.stderr)
151
- self.shutdown(2)
152
- break
153
- if self.done.wait(self.interval):
154
- break
148
+ while not self.done.wait(self.interval):
149
+ self._check_errfile()
150
+
151
+ def _check_errfile(self):
152
+ if self.errfile and self.errfile.exists():
153
+ message = f'Shutting down due to error file: {self.errfile}'
154
+ print(message, file=sys.stderr)
155
+ self.shutdown(exitcode=2)
155
156
 
156
157
 
157
158
  context = Context()
@@ -141,8 +141,11 @@ class ServerSocket:
141
141
  conn.recvbuf = buffers.RecvBuffer(maxsize=self.options.max_msg_size)
142
142
  try:
143
143
  conn.recvbuf.recv(conn.sock)
144
- except ConnectionResetError:
145
- self._disconnect(conn)
144
+ except OSError as e:
145
+ # For example:
146
+ # - ConnectionResetError
147
+ # - TimeoutError: [Errno 110] Connection timed out
148
+ self._disconnect(conn, e)
146
149
  return
147
150
  if conn.recvbuf.done():
148
151
  if self.recvq.qsize() > self.options.max_recv_queue:
@@ -150,8 +153,10 @@ class ServerSocket:
150
153
  self.recvq.put((conn.addr, conn.recvbuf.result()))
151
154
  conn.recvbuf = None
152
155
 
153
- def _disconnect(self, conn):
154
- self._log(f'Closed connection to {conn.addr[0]}:{conn.addr[1]}')
156
+ def _disconnect(self, conn, e):
157
+ detail = f'{type(e).__name__}'
158
+ detail = f'{detail}: {e}' if str(e) else detail
159
+ self._log(f'Closed connection to {conn.addr[0]}:{conn.addr[1]} ({detail})')
155
160
  conn = self.conns.pop(conn.addr)
156
161
  if conn.sendbufs:
157
162
  count = len(conn.sendbufs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: portal
3
- Version: 3.1.8
3
+ Version: 3.1.10
4
4
  Summary: Fast and reliable distributed systems in Python
5
5
  Home-page: http://github.com/danijar/portal
6
6
  Author: Danijar Hafner
@@ -110,7 +110,8 @@ class TestBatching:
110
110
  client.close()
111
111
  server.close()
112
112
 
113
- def test_shape_mismatch(self):
113
+ @pytest.mark.parametrize('repeat', range(5))
114
+ def test_shape_mismatch(self, repeat):
114
115
  port = portal.free_port()
115
116
  server = portal.BatchServer(port, errors=False)
116
117
  server.bind('fn', lambda x: x, batch=2)
@@ -24,31 +24,30 @@ class TestErrfile:
24
24
  assert 'line' in content
25
25
  assert 'in fn' in content
26
26
 
27
- @pytest.mark.parametrize('repeat', range(3))
27
+ @pytest.mark.parametrize('repeat', range(5))
28
28
  def test_sibling_procs(self, tmpdir, repeat):
29
29
  errfile = pathlib.Path(tmpdir) / 'error'
30
- ready = portal.context.mp.Semaphore(0)
30
+ barrier = portal.context.mp.Barrier(3)
31
31
 
32
- def fn1(ready, errfile):
32
+ def fn1(barrier, errfile):
33
33
  portal.setup(errfile=errfile, interval=0.1)
34
- ready.release()
34
+ barrier.wait()
35
35
  raise ValueError('reason')
36
36
 
37
- def fn2(ready, errfile):
37
+ def fn2(barrier, errfile):
38
38
  portal.setup(errfile=errfile, interval=0.1)
39
- ready.release()
39
+ barrier.wait()
40
40
  while True:
41
41
  time.sleep(0.1)
42
42
 
43
- worker1 = portal.Process(fn1, ready, errfile, name='worker1', start=True)
44
- worker2 = portal.Process(fn2, ready, errfile, name='worker2', start=True)
45
- ready.acquire()
46
- ready.acquire()
43
+ worker1 = portal.Process(fn1, barrier, errfile, start=True)
44
+ worker2 = portal.Process(fn2, barrier, errfile, start=True)
45
+ barrier.wait()
47
46
  worker1.join()
48
47
  worker2.join()
49
48
  content = errfile.read_text()
50
49
  first_line = content.split('\n')[0]
51
- assert "Error in 'worker1' (ValueError: reason):" == first_line
50
+ assert "Error in 'fn1' (ValueError: reason):" == first_line
52
51
  assert not worker1.running
53
52
  assert not worker2.running
54
53
  assert worker1.exitcode == 1
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes