portal 3.1.9__tar.gz → 3.1.11__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.9/portal.egg-info → portal-3.1.11}/PKG-INFO +1 -1
  2. {portal-3.1.9 → portal-3.1.11}/portal/__init__.py +1 -1
  3. {portal-3.1.9 → portal-3.1.11}/portal/batching.py +1 -0
  4. {portal-3.1.9 → portal-3.1.11}/portal/server_socket.py +10 -4
  5. {portal-3.1.9 → portal-3.1.11}/portal/utils.py +2 -2
  6. {portal-3.1.9 → portal-3.1.11/portal.egg-info}/PKG-INFO +1 -1
  7. {portal-3.1.9 → portal-3.1.11}/tests/test_batching.py +2 -1
  8. {portal-3.1.9 → portal-3.1.11}/LICENSE +0 -0
  9. {portal-3.1.9 → portal-3.1.11}/MANIFEST.in +0 -0
  10. {portal-3.1.9 → portal-3.1.11}/README.md +0 -0
  11. {portal-3.1.9 → portal-3.1.11}/portal/buffers.py +0 -0
  12. {portal-3.1.9 → portal-3.1.11}/portal/client.py +0 -0
  13. {portal-3.1.9 → portal-3.1.11}/portal/client_socket.py +0 -0
  14. {portal-3.1.9 → portal-3.1.11}/portal/contextlib.py +0 -0
  15. {portal-3.1.9 → portal-3.1.11}/portal/packlib.py +0 -0
  16. {portal-3.1.9 → portal-3.1.11}/portal/poollib.py +0 -0
  17. {portal-3.1.9 → portal-3.1.11}/portal/process.py +0 -0
  18. {portal-3.1.9 → portal-3.1.11}/portal/server.py +0 -0
  19. {portal-3.1.9 → portal-3.1.11}/portal/sharray.py +0 -0
  20. {portal-3.1.9 → portal-3.1.11}/portal/thread.py +0 -0
  21. {portal-3.1.9 → portal-3.1.11}/portal.egg-info/SOURCES.txt +0 -0
  22. {portal-3.1.9 → portal-3.1.11}/portal.egg-info/dependency_links.txt +0 -0
  23. {portal-3.1.9 → portal-3.1.11}/portal.egg-info/requires.txt +0 -0
  24. {portal-3.1.9 → portal-3.1.11}/portal.egg-info/top_level.txt +0 -0
  25. {portal-3.1.9 → portal-3.1.11}/pyproject.toml +0 -0
  26. {portal-3.1.9 → portal-3.1.11}/requirements.txt +0 -0
  27. {portal-3.1.9 → portal-3.1.11}/setup.cfg +0 -0
  28. {portal-3.1.9 → portal-3.1.11}/setup.py +0 -0
  29. {portal-3.1.9 → portal-3.1.11}/tests/test_client.py +0 -0
  30. {portal-3.1.9 → portal-3.1.11}/tests/test_errfile.py +0 -0
  31. {portal-3.1.9 → portal-3.1.11}/tests/test_pack.py +0 -0
  32. {portal-3.1.9 → portal-3.1.11}/tests/test_process.py +0 -0
  33. {portal-3.1.9 → portal-3.1.11}/tests/test_server.py +0 -0
  34. {portal-3.1.9 → portal-3.1.11}/tests/test_socket.py +0 -0
  35. {portal-3.1.9 → portal-3.1.11}/tests/test_thread.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: portal
3
- Version: 3.1.9
3
+ Version: 3.1.11
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.9'
1
+ __version__ = '3.1.11'
2
2
 
3
3
  import multiprocessing as mp
4
4
  try:
@@ -19,6 +19,7 @@ class BatchServer:
19
19
  self, port, name='Server', workers=1, errors=True,
20
20
  process=True, shmem=False, **kwargs):
21
21
  inner_port = utils.free_port()
22
+ assert port != inner_port, (port, inner_port)
22
23
  self.name = name
23
24
  self.server = server.Server(inner_port, name, workers, errors, **kwargs)
24
25
  if process:
@@ -48,6 +48,7 @@ class ServerSocket:
48
48
  self.addr = (self.options.host, port)
49
49
  self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
50
50
  # self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
51
+ self._log(f'Binding to {self.addr[0]}:{self.addr[1]}')
51
52
  self.sock.bind(self.addr)
52
53
  self.sock.setblocking(False)
53
54
  self.sock.listen()
@@ -141,8 +142,11 @@ class ServerSocket:
141
142
  conn.recvbuf = buffers.RecvBuffer(maxsize=self.options.max_msg_size)
142
143
  try:
143
144
  conn.recvbuf.recv(conn.sock)
144
- except ConnectionResetError:
145
- self._disconnect(conn)
145
+ except OSError as e:
146
+ # For example:
147
+ # - ConnectionResetError
148
+ # - TimeoutError: [Errno 110] Connection timed out
149
+ self._disconnect(conn, e)
146
150
  return
147
151
  if conn.recvbuf.done():
148
152
  if self.recvq.qsize() > self.options.max_recv_queue:
@@ -150,8 +154,10 @@ class ServerSocket:
150
154
  self.recvq.put((conn.addr, conn.recvbuf.result()))
151
155
  conn.recvbuf = None
152
156
 
153
- def _disconnect(self, conn):
154
- self._log(f'Closed connection to {conn.addr[0]}:{conn.addr[1]}')
157
+ def _disconnect(self, conn, e):
158
+ detail = f'{type(e).__name__}'
159
+ detail = f'{detail}: {e}' if str(e) else detail
160
+ self._log(f'Closed connection to {conn.addr[0]}:{conn.addr[1]} ({detail})')
155
161
  conn = self.conns.pop(conn.addr)
156
162
  if conn.sendbufs:
157
163
  count = len(conn.sendbufs)
@@ -78,13 +78,13 @@ def kill_procs(procs, timeout=3):
78
78
  if p.status() != psutil.STATUS_ZOMBIE else None), procs)
79
79
 
80
80
 
81
- def free_port():
81
+ def free_port(low=10000, high=50000):
82
82
  # Return a port that is currently free. This function is not thread or
83
83
  # process safe, because there is no way to guarantee that the port will still
84
84
  # be free at the time it will be used.
85
85
  rng = np.random.default_rng()
86
86
  while True:
87
- port = int(rng.integers(2000, 7000))
87
+ port = int(rng.integers(low, high))
88
88
  with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
89
89
  if s.connect_ex(('', port)):
90
90
  return port
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: portal
3
- Version: 3.1.9
3
+ Version: 3.1.11
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)
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