portal 3.4.2__tar.gz → 3.4.4__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.4.2/portal.egg-info → portal-3.4.4}/PKG-INFO +1 -1
  2. {portal-3.4.2 → portal-3.4.4}/portal/__init__.py +1 -1
  3. {portal-3.4.2 → portal-3.4.4}/portal/client_socket.py +30 -26
  4. {portal-3.4.2 → portal-3.4.4}/portal/server_socket.py +8 -2
  5. {portal-3.4.2 → portal-3.4.4/portal.egg-info}/PKG-INFO +1 -1
  6. {portal-3.4.2 → portal-3.4.4}/LICENSE +0 -0
  7. {portal-3.4.2 → portal-3.4.4}/MANIFEST.in +0 -0
  8. {portal-3.4.2 → portal-3.4.4}/README.md +0 -0
  9. {portal-3.4.2 → portal-3.4.4}/portal/batching.py +0 -0
  10. {portal-3.4.2 → portal-3.4.4}/portal/buffers.py +0 -0
  11. {portal-3.4.2 → portal-3.4.4}/portal/client.py +0 -0
  12. {portal-3.4.2 → portal-3.4.4}/portal/contextlib.py +0 -0
  13. {portal-3.4.2 → portal-3.4.4}/portal/packlib.py +0 -0
  14. {portal-3.4.2 → portal-3.4.4}/portal/poollib.py +0 -0
  15. {portal-3.4.2 → portal-3.4.4}/portal/process.py +0 -0
  16. {portal-3.4.2 → portal-3.4.4}/portal/server.py +0 -0
  17. {portal-3.4.2 → portal-3.4.4}/portal/sharray.py +0 -0
  18. {portal-3.4.2 → portal-3.4.4}/portal/thread.py +0 -0
  19. {portal-3.4.2 → portal-3.4.4}/portal/utils.py +0 -0
  20. {portal-3.4.2 → portal-3.4.4}/portal.egg-info/SOURCES.txt +0 -0
  21. {portal-3.4.2 → portal-3.4.4}/portal.egg-info/dependency_links.txt +0 -0
  22. {portal-3.4.2 → portal-3.4.4}/portal.egg-info/requires.txt +0 -0
  23. {portal-3.4.2 → portal-3.4.4}/portal.egg-info/top_level.txt +0 -0
  24. {portal-3.4.2 → portal-3.4.4}/pyproject.toml +0 -0
  25. {portal-3.4.2 → portal-3.4.4}/requirements.txt +0 -0
  26. {portal-3.4.2 → portal-3.4.4}/setup.cfg +0 -0
  27. {portal-3.4.2 → portal-3.4.4}/setup.py +0 -0
  28. {portal-3.4.2 → portal-3.4.4}/tests/test_batching.py +0 -0
  29. {portal-3.4.2 → portal-3.4.4}/tests/test_client.py +0 -0
  30. {portal-3.4.2 → portal-3.4.4}/tests/test_errfile.py +0 -0
  31. {portal-3.4.2 → portal-3.4.4}/tests/test_pack.py +0 -0
  32. {portal-3.4.2 → portal-3.4.4}/tests/test_process.py +0 -0
  33. {portal-3.4.2 → portal-3.4.4}/tests/test_server.py +0 -0
  34. {portal-3.4.2 → portal-3.4.4}/tests/test_socket.py +0 -0
  35. {portal-3.4.2 → portal-3.4.4}/tests/test_thread.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: portal
3
- Version: 3.4.2
3
+ Version: 3.4.4
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.4.2'
1
+ __version__ = '3.4.4'
2
2
 
3
3
  import multiprocessing as mp
4
4
  try:
@@ -30,6 +30,7 @@ class Options:
30
30
  logging: bool = True
31
31
  logging_color: str = 'yellow'
32
32
  connect_wait: float = 0.1
33
+ idle_sleep: float = 0.0001
33
34
 
34
35
 
35
36
  class ClientSocket:
@@ -129,33 +130,36 @@ class ClientSocket:
129
130
 
130
131
  try:
131
132
 
132
- # TODO: According to the py-spy profiler, the GIL is held during
133
- # polling. Is there a way to avoid that?
133
+ idle = True
134
134
  pairs = poll.poll(0.2)
135
- if not pairs:
136
- continue
137
- _, mask = pairs[0]
138
-
139
- if mask & select.POLLIN:
140
- try:
141
- recvbuf.recv(sock)
142
- if recvbuf.done():
143
- if self.recvq.qsize() > self.options.max_recv_queue:
144
- raise RuntimeError('Too many incoming messages enqueued')
145
- msg = recvbuf.result()
146
- self.recvq.put(msg)
147
- [x(msg) for x in self.callbacks_recv]
148
- recvbuf = buffers.RecvBuffer(maxsize=self.options.max_msg_size)
149
- except BlockingIOError:
150
- pass
151
-
152
- if self.sendq and mask & select.POLLOUT:
153
- try:
154
- self.sendq[0].send(sock)
155
- if self.sendq[0].done():
156
- self.sendq.popleft()
157
- except BlockingIOError:
158
- pass
135
+ if pairs:
136
+ _, mask = pairs[0]
137
+
138
+ if mask & select.POLLIN:
139
+ try:
140
+ recvbuf.recv(sock)
141
+ idle = False
142
+ if recvbuf.done():
143
+ if self.recvq.qsize() > self.options.max_recv_queue:
144
+ raise RuntimeError('Too many incoming messages enqueued')
145
+ msg = recvbuf.result()
146
+ self.recvq.put(msg)
147
+ [x(msg) for x in self.callbacks_recv]
148
+ recvbuf = buffers.RecvBuffer(maxsize=self.options.max_msg_size)
149
+ except BlockingIOError:
150
+ pass
151
+
152
+ if self.sendq and mask & select.POLLOUT:
153
+ try:
154
+ self.sendq[0].send(sock)
155
+ idle = False
156
+ if self.sendq[0].done():
157
+ self.sendq.popleft()
158
+ except BlockingIOError:
159
+ pass
160
+
161
+ if idle and self.options.idle_sleep:
162
+ time.sleep(self.options.idle_sleep)
159
163
 
160
164
  except OSError as e:
161
165
  detail = f'{type(e).__name__}'
@@ -3,6 +3,7 @@ import dataclasses
3
3
  import queue
4
4
  import selectors
5
5
  import socket
6
+ import time
6
7
 
7
8
  from . import buffers
8
9
  from . import contextlib
@@ -31,6 +32,7 @@ class Options:
31
32
  max_send_queue: int = 4096
32
33
  logging: bool = True
33
34
  logging_color: str = 'blue'
35
+ idle_sleep: float = 0.0001
34
36
 
35
37
 
36
38
  class ServerSocket:
@@ -103,15 +105,16 @@ class ServerSocket:
103
105
  def _loop(self):
104
106
  try:
105
107
  while self.running or self._numsending():
108
+ idle = True
106
109
  writeable = []
107
- # TODO: According to the py-spy profiler, the GIL is held during
108
- # polling. Is there a way to avoid that?
109
110
  for key, mask in self.sel.select(timeout=0.2):
110
111
  if key.data is None and self.reading:
111
112
  assert mask & selectors.EVENT_READ
112
113
  self._accept(key.fileobj)
114
+ idle = False
113
115
  elif mask & selectors.EVENT_READ and self.reading:
114
116
  self._recv(key.data)
117
+ idle = False
115
118
  elif mask & selectors.EVENT_WRITE:
116
119
  writeable.append(key.data)
117
120
  for conn in writeable:
@@ -119,6 +122,7 @@ class ServerSocket:
119
122
  continue
120
123
  try:
121
124
  conn.sendbufs[0].send(conn.sock)
125
+ idle = False
122
126
  if conn.sendbufs[0].done():
123
127
  conn.sendbufs.popleft()
124
128
  except BlockingIOError:
@@ -127,6 +131,8 @@ class ServerSocket:
127
131
  # The client is gone but we may have buffered messages left to
128
132
  # read, so we keep the socket open until recv() fails.
129
133
  pass
134
+ if idle and self.options.idle_sleep:
135
+ time.sleep(self.options.idle_sleep)
130
136
  except Exception as e:
131
137
  self.error = e
132
138
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: portal
3
- Version: 3.4.2
3
+ Version: 3.4.4
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