portal 3.1.11__tar.gz → 3.1.12__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.11/portal.egg-info → portal-3.1.12}/PKG-INFO +1 -1
  2. {portal-3.1.11 → portal-3.1.12}/portal/__init__.py +1 -1
  3. {portal-3.1.11 → portal-3.1.12}/portal/contextlib.py +11 -0
  4. {portal-3.1.11 → portal-3.1.12}/portal/utils.py +7 -7
  5. {portal-3.1.11 → portal-3.1.12/portal.egg-info}/PKG-INFO +1 -1
  6. {portal-3.1.11 → portal-3.1.12}/LICENSE +0 -0
  7. {portal-3.1.11 → portal-3.1.12}/MANIFEST.in +0 -0
  8. {portal-3.1.11 → portal-3.1.12}/README.md +0 -0
  9. {portal-3.1.11 → portal-3.1.12}/portal/batching.py +0 -0
  10. {portal-3.1.11 → portal-3.1.12}/portal/buffers.py +0 -0
  11. {portal-3.1.11 → portal-3.1.12}/portal/client.py +0 -0
  12. {portal-3.1.11 → portal-3.1.12}/portal/client_socket.py +0 -0
  13. {portal-3.1.11 → portal-3.1.12}/portal/packlib.py +0 -0
  14. {portal-3.1.11 → portal-3.1.12}/portal/poollib.py +0 -0
  15. {portal-3.1.11 → portal-3.1.12}/portal/process.py +0 -0
  16. {portal-3.1.11 → portal-3.1.12}/portal/server.py +0 -0
  17. {portal-3.1.11 → portal-3.1.12}/portal/server_socket.py +0 -0
  18. {portal-3.1.11 → portal-3.1.12}/portal/sharray.py +0 -0
  19. {portal-3.1.11 → portal-3.1.12}/portal/thread.py +0 -0
  20. {portal-3.1.11 → portal-3.1.12}/portal.egg-info/SOURCES.txt +0 -0
  21. {portal-3.1.11 → portal-3.1.12}/portal.egg-info/dependency_links.txt +0 -0
  22. {portal-3.1.11 → portal-3.1.12}/portal.egg-info/requires.txt +0 -0
  23. {portal-3.1.11 → portal-3.1.12}/portal.egg-info/top_level.txt +0 -0
  24. {portal-3.1.11 → portal-3.1.12}/pyproject.toml +0 -0
  25. {portal-3.1.11 → portal-3.1.12}/requirements.txt +0 -0
  26. {portal-3.1.11 → portal-3.1.12}/setup.cfg +0 -0
  27. {portal-3.1.11 → portal-3.1.12}/setup.py +0 -0
  28. {portal-3.1.11 → portal-3.1.12}/tests/test_batching.py +0 -0
  29. {portal-3.1.11 → portal-3.1.12}/tests/test_client.py +0 -0
  30. {portal-3.1.11 → portal-3.1.12}/tests/test_errfile.py +0 -0
  31. {portal-3.1.11 → portal-3.1.12}/tests/test_pack.py +0 -0
  32. {portal-3.1.11 → portal-3.1.12}/tests/test_process.py +0 -0
  33. {portal-3.1.11 → portal-3.1.12}/tests/test_server.py +0 -0
  34. {portal-3.1.11 → portal-3.1.12}/tests/test_socket.py +0 -0
  35. {portal-3.1.11 → portal-3.1.12}/tests/test_thread.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: portal
3
- Version: 3.1.11
3
+ Version: 3.1.12
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.11'
1
+ __version__ = '3.1.12'
2
2
 
3
3
  import multiprocessing as mp
4
4
  try:
@@ -61,6 +61,7 @@ class Context:
61
61
  assert hasattr(errfile, 'exists') and hasattr(errfile, 'write_text')
62
62
  self.errfile = errfile
63
63
  self._check_errfile()
64
+ self._install_excepthook()
64
65
 
65
66
  if interval:
66
67
  assert isinstance(interval, (int, float))
@@ -148,6 +149,16 @@ class Context:
148
149
  while not self.done.wait(self.interval):
149
150
  self._check_errfile()
150
151
 
152
+ def _install_excepthook(self):
153
+ existing = sys.excepthook
154
+ def patched(typ, val, tb):
155
+ if self.errfile:
156
+ message = ''.join(traceback.format_exception(typ, val, tb)).strip('\n')
157
+ self.errfile.write_text(message)
158
+ print(f'Wrote errorfile: {self.errfile}', file=sys.stderr)
159
+ return existing(typ, val, tb)
160
+ sys.excepthook = patched
161
+
151
162
  def _check_errfile(self):
152
163
  if self.errfile and self.errfile.exists():
153
164
  message = f'Shutting down due to error file: {self.errfile}'
@@ -78,16 +78,16 @@ 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(low=10000, high=50000):
81
+ def free_port():
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
- rng = np.random.default_rng()
86
- while True:
87
- port = int(rng.integers(low, high))
88
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
89
- if s.connect_ex(('', port)):
90
- return port
85
+ sock = socket.socket()
86
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
87
+ sock.bind(('localhost', 0))
88
+ port = sock.getsockname()[1]
89
+ sock.close()
90
+ return port
91
91
 
92
92
 
93
93
  def style(color=None, background=None, bold=None, underline=None, reset=None):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: portal
3
- Version: 3.1.11
3
+ Version: 3.1.12
4
4
  Summary: Fast and reliable distributed systems in Python
5
5
  Home-page: http://github.com/danijar/portal
6
6
  Author: Danijar Hafner
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
File without changes
File without changes