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