flpit 0.4.2.dev11__tar.gz → 0.5.0__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 (28) hide show
  1. {flpit-0.4.2.dev11 → flpit-0.5.0}/PKG-INFO +27 -21
  2. {flpit-0.4.2.dev11 → flpit-0.5.0}/README.md +26 -20
  3. {flpit-0.4.2.dev11 → flpit-0.5.0}/pyproject.toml +1 -1
  4. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/asyncio_bridge.py +1 -1
  5. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/core/linq.py +13 -1
  6. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/task.py +22 -21
  7. {flpit-0.4.2.dev11 → flpit-0.5.0}/.gitignore +0 -0
  8. {flpit-0.4.2.dev11 → flpit-0.5.0}/LICENSE +0 -0
  9. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flp/__init__.py +0 -0
  10. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/__init__.py +0 -0
  11. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/channels.py +0 -0
  12. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/concurrent.py +0 -0
  13. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/core/__init__.py +0 -0
  14. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/core/_grouping.py +0 -0
  15. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/core/_index.py +0 -0
  16. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/core/_join.py +0 -0
  17. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/core/_lookup.py +0 -0
  18. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/core/_zip.py +0 -0
  19. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/core/async_linq.py +0 -0
  20. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/core/comparers.py +0 -0
  21. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/csv.py +0 -0
  22. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/flp.py +0 -0
  23. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/json/__init__.py +0 -0
  24. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/json/_core.py +0 -0
  25. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/json/_msgspec.py +0 -0
  26. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/json/_native.py +0 -0
  27. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/py.typed +0 -0
  28. {flpit-0.4.2.dev11 → flpit-0.5.0}/src/flpit/threading.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: flpit
3
- Version: 0.4.2.dev11
3
+ Version: 0.5.0
4
4
  Summary: Fluent LINQ for Python — flip your iterables
5
5
  Project-URL: Homepage, https://github.com/riemar/flpit
6
6
  Project-URL: Documentation, https://riemar.github.io/flpit/
@@ -153,7 +153,7 @@ Distributed under the MIT License. See `LICENSE` for more information.
153
153
  | │ ├── test_first.py | 8 |
154
154
  | │ ├── test_first_or_default.py | 8 |
155
155
  | │ ├── test_full_join.py | 11 |
156
- | │ ├── test_group_by.py | 5 |
156
+ | │ ├── test_group_by.py | 6 |
157
157
  | │ ├── test_group_join.py | 9 |
158
158
  | │ ├── test_index.py | 8 |
159
159
  | │ ├── test_intersect.py | 12 |
@@ -162,9 +162,9 @@ Distributed under the MIT License. See `LICENSE` for more information.
162
162
  | │ ├── test_last_or_default.py | 8 |
163
163
  | │ ├── test_left_join.py | 10 |
164
164
  | │ ├── test_max.py | 11 |
165
- | │ ├── test_max_by.py | 13 |
165
+ | │ ├── test_max_by.py | 12 |
166
166
  | │ ├── test_min.py | 11 |
167
- | │ ├── test_min_by.py | 13 |
167
+ | │ ├── test_min_by.py | 12 |
168
168
  | │ ├── test_of_type.py | 5 |
169
169
  | │ ├── test_order_by.py | 18 |
170
170
  | │ ├── test_prepend.py | 19 |
@@ -198,7 +198,7 @@ Distributed under the MIT License. See `LICENSE` for more information.
198
198
  | │ ├── test_rendezvous_channel.py | 104 |
199
199
  | │ └── test_unbounded_channel.py | 338 |
200
200
  | ├── concurrent/ | |
201
- | │ ├── test_concurrent_bag.py | 130 |
201
+ | │ ├── test_concurrent_bag.py | 131 |
202
202
  | │ ├── test_concurrent_dictionary.py | 56 |
203
203
  | │ ├── test_concurrent_dictionary_generic.py | 1236 |
204
204
  | │ ├── test_concurrent_queue.py | 130 |
@@ -214,7 +214,7 @@ Distributed under the MIT License. See `LICENSE` for more information.
214
214
  | │ ├── test_chunk.py | 22 |
215
215
  | │ ├── test_concat.py | 64 |
216
216
  | │ ├── test_contains.py | 108 |
217
- | │ ├── test_count.py | 37 |
217
+ | │ ├── test_count.py | 64 |
218
218
  | │ ├── test_default_if_empty.py | 37 |
219
219
  | │ ├── test_distinct.py | 87 |
220
220
  | │ ├── test_element_at.py | 43 |
@@ -222,7 +222,7 @@ Distributed under the MIT License. See `LICENSE` for more information.
222
222
  | │ ├── test_first.py | 29 |
223
223
  | │ ├── test_first_or_default.py | 50 |
224
224
  | │ ├── test_full_join.py | 37 |
225
- | │ ├── test_generic_list.py | 95 |
225
+ | │ ├── test_generic_list.py | 87 |
226
226
  | │ ├── test_group_by.py | 23 |
227
227
  | │ ├── test_group_join.py | 53 |
228
228
  | │ ├── test_index.py | 6 |
@@ -231,23 +231,23 @@ Distributed under the MIT License. See `LICENSE` for more information.
231
231
  | │ ├── test_last.py | 29 |
232
232
  | │ ├── test_last_or_default.py | 45 |
233
233
  | │ ├── test_left_join.py | 47 |
234
- | │ ├── test_max.py | 1100 |
235
- | │ ├── test_min.py | 968 |
234
+ | │ ├── test_max.py | 1098 |
235
+ | │ ├── test_min.py | 966 |
236
236
  | │ ├── test_of_type.py | 38 |
237
- | │ ├── test_order_by.py | 100 |
238
- | │ ├── test_order_descending_by.py | 45 |
237
+ | │ ├── test_order_by.py | 104 |
238
+ | │ ├── test_order_descending_by.py | 46 |
239
239
  | │ ├── test_reverse.py | 35 |
240
- | │ ├── test_select.py | 140 |
240
+ | │ ├── test_select.py | 143 |
241
241
  | │ ├── test_select_many.py | 85 |
242
242
  | │ ├── test_single.py | 34 |
243
243
  | │ ├── test_single_or_default.py | 48 |
244
- | │ ├── test_skip.py | 75 |
244
+ | │ ├── test_skip.py | 77 |
245
245
  | │ ├── test_skip_last.py | 1221 |
246
- | │ ├── test_sum.py | 134 |
247
- | │ ├── test_take.py | 39 |
246
+ | │ ├── test_sum.py | 154 |
247
+ | │ ├── test_take.py | 73 |
248
248
  | │ ├── test_take_last.py | 1221 |
249
- | │ ├── test_then_by.py | 40 |
250
- | │ ├── test_then_descending_by.py | 34 |
249
+ | │ ├── test_then_by.py | 38 |
250
+ | │ ├── test_then_descending_by.py | 32 |
251
251
  | │ ├── test_to_dictionary.py | 32 |
252
252
  | │ ├── test_to_list.py | 40 |
253
253
  | │ ├── test_to_lookup.py | 26 |
@@ -255,20 +255,26 @@ Distributed under the MIT License. See `LICENSE` for more information.
255
255
  | │ ├── test_where.py | 76 |
256
256
  | │ └── test_zip.py | 101 |
257
257
  | ├── task/ | |
258
+ | │ ├── test_aggregate_exception.py | 1 |
258
259
  | │ ├── test_cancellation.py | 69 |
259
- | │ ├── test_task_completion_source.py | 26 |
260
+ | │ ├── test_method_coverage.py | 30 |
261
+ | │ ├── test_method_coverage_when_all.py | 13 |
262
+ | │ ├── test_operation_canceled_exception.py | 0 |
263
+ | │ ├── test_task_canceled_exception.py | 1 |
264
+ | │ ├── test_task_completion_source.py | 25 |
265
+ | │ ├── test_task_completion_source_tresult.py | 5 |
260
266
  | │ ├── test_task_continue_with.py | 15 |
261
267
  | │ ├── test_task_continue_with_func_and_action.py | 16 |
262
268
  | │ ├── test_task_continue_with_func_and_action_args.py | 20 |
263
269
  | │ ├── test_task_factory.py | 3 |
264
- | │ ├── test_task_rt.py | 13 |
265
- | │ ├── test_task_rt_core.py | 27 |
270
+ | │ ├── test_task_rt.py | 7 |
271
+ | │ ├── test_task_rt_core.py | 32 |
266
272
  | │ └── test_task_wait_all_any.py | 62 |
267
273
  | └── threading/ | |
268
274
  | ├── test_semaphore_slim.py | 39 |
269
275
  | ├── test_semaphore_slim_cancellation.py | 4 |
270
276
  | └── test_thread_local.py | 15 |
271
277
  --------------------------------------------------------------------------------
272
- | GRAND TOTALS | 10725 |
278
+ | GRAND TOTALS | 10848 |
273
279
  ================================================================================
274
280
  ```
@@ -122,7 +122,7 @@ Distributed under the MIT License. See `LICENSE` for more information.
122
122
  | │ ├── test_first.py | 8 |
123
123
  | │ ├── test_first_or_default.py | 8 |
124
124
  | │ ├── test_full_join.py | 11 |
125
- | │ ├── test_group_by.py | 5 |
125
+ | │ ├── test_group_by.py | 6 |
126
126
  | │ ├── test_group_join.py | 9 |
127
127
  | │ ├── test_index.py | 8 |
128
128
  | │ ├── test_intersect.py | 12 |
@@ -131,9 +131,9 @@ Distributed under the MIT License. See `LICENSE` for more information.
131
131
  | │ ├── test_last_or_default.py | 8 |
132
132
  | │ ├── test_left_join.py | 10 |
133
133
  | │ ├── test_max.py | 11 |
134
- | │ ├── test_max_by.py | 13 |
134
+ | │ ├── test_max_by.py | 12 |
135
135
  | │ ├── test_min.py | 11 |
136
- | │ ├── test_min_by.py | 13 |
136
+ | │ ├── test_min_by.py | 12 |
137
137
  | │ ├── test_of_type.py | 5 |
138
138
  | │ ├── test_order_by.py | 18 |
139
139
  | │ ├── test_prepend.py | 19 |
@@ -167,7 +167,7 @@ Distributed under the MIT License. See `LICENSE` for more information.
167
167
  | │ ├── test_rendezvous_channel.py | 104 |
168
168
  | │ └── test_unbounded_channel.py | 338 |
169
169
  | ├── concurrent/ | |
170
- | │ ├── test_concurrent_bag.py | 130 |
170
+ | │ ├── test_concurrent_bag.py | 131 |
171
171
  | │ ├── test_concurrent_dictionary.py | 56 |
172
172
  | │ ├── test_concurrent_dictionary_generic.py | 1236 |
173
173
  | │ ├── test_concurrent_queue.py | 130 |
@@ -183,7 +183,7 @@ Distributed under the MIT License. See `LICENSE` for more information.
183
183
  | │ ├── test_chunk.py | 22 |
184
184
  | │ ├── test_concat.py | 64 |
185
185
  | │ ├── test_contains.py | 108 |
186
- | │ ├── test_count.py | 37 |
186
+ | │ ├── test_count.py | 64 |
187
187
  | │ ├── test_default_if_empty.py | 37 |
188
188
  | │ ├── test_distinct.py | 87 |
189
189
  | │ ├── test_element_at.py | 43 |
@@ -191,7 +191,7 @@ Distributed under the MIT License. See `LICENSE` for more information.
191
191
  | │ ├── test_first.py | 29 |
192
192
  | │ ├── test_first_or_default.py | 50 |
193
193
  | │ ├── test_full_join.py | 37 |
194
- | │ ├── test_generic_list.py | 95 |
194
+ | │ ├── test_generic_list.py | 87 |
195
195
  | │ ├── test_group_by.py | 23 |
196
196
  | │ ├── test_group_join.py | 53 |
197
197
  | │ ├── test_index.py | 6 |
@@ -200,23 +200,23 @@ Distributed under the MIT License. See `LICENSE` for more information.
200
200
  | │ ├── test_last.py | 29 |
201
201
  | │ ├── test_last_or_default.py | 45 |
202
202
  | │ ├── test_left_join.py | 47 |
203
- | │ ├── test_max.py | 1100 |
204
- | │ ├── test_min.py | 968 |
203
+ | │ ├── test_max.py | 1098 |
204
+ | │ ├── test_min.py | 966 |
205
205
  | │ ├── test_of_type.py | 38 |
206
- | │ ├── test_order_by.py | 100 |
207
- | │ ├── test_order_descending_by.py | 45 |
206
+ | │ ├── test_order_by.py | 104 |
207
+ | │ ├── test_order_descending_by.py | 46 |
208
208
  | │ ├── test_reverse.py | 35 |
209
- | │ ├── test_select.py | 140 |
209
+ | │ ├── test_select.py | 143 |
210
210
  | │ ├── test_select_many.py | 85 |
211
211
  | │ ├── test_single.py | 34 |
212
212
  | │ ├── test_single_or_default.py | 48 |
213
- | │ ├── test_skip.py | 75 |
213
+ | │ ├── test_skip.py | 77 |
214
214
  | │ ├── test_skip_last.py | 1221 |
215
- | │ ├── test_sum.py | 134 |
216
- | │ ├── test_take.py | 39 |
215
+ | │ ├── test_sum.py | 154 |
216
+ | │ ├── test_take.py | 73 |
217
217
  | │ ├── test_take_last.py | 1221 |
218
- | │ ├── test_then_by.py | 40 |
219
- | │ ├── test_then_descending_by.py | 34 |
218
+ | │ ├── test_then_by.py | 38 |
219
+ | │ ├── test_then_descending_by.py | 32 |
220
220
  | │ ├── test_to_dictionary.py | 32 |
221
221
  | │ ├── test_to_list.py | 40 |
222
222
  | │ ├── test_to_lookup.py | 26 |
@@ -224,20 +224,26 @@ Distributed under the MIT License. See `LICENSE` for more information.
224
224
  | │ ├── test_where.py | 76 |
225
225
  | │ └── test_zip.py | 101 |
226
226
  | ├── task/ | |
227
+ | │ ├── test_aggregate_exception.py | 1 |
227
228
  | │ ├── test_cancellation.py | 69 |
228
- | │ ├── test_task_completion_source.py | 26 |
229
+ | │ ├── test_method_coverage.py | 30 |
230
+ | │ ├── test_method_coverage_when_all.py | 13 |
231
+ | │ ├── test_operation_canceled_exception.py | 0 |
232
+ | │ ├── test_task_canceled_exception.py | 1 |
233
+ | │ ├── test_task_completion_source.py | 25 |
234
+ | │ ├── test_task_completion_source_tresult.py | 5 |
229
235
  | │ ├── test_task_continue_with.py | 15 |
230
236
  | │ ├── test_task_continue_with_func_and_action.py | 16 |
231
237
  | │ ├── test_task_continue_with_func_and_action_args.py | 20 |
232
238
  | │ ├── test_task_factory.py | 3 |
233
- | │ ├── test_task_rt.py | 13 |
234
- | │ ├── test_task_rt_core.py | 27 |
239
+ | │ ├── test_task_rt.py | 7 |
240
+ | │ ├── test_task_rt_core.py | 32 |
235
241
  | │ └── test_task_wait_all_any.py | 62 |
236
242
  | └── threading/ | |
237
243
  | ├── test_semaphore_slim.py | 39 |
238
244
  | ├── test_semaphore_slim_cancellation.py | 4 |
239
245
  | └── test_thread_local.py | 15 |
240
246
  --------------------------------------------------------------------------------
241
- | GRAND TOTALS | 10725 |
247
+ | GRAND TOTALS | 10848 |
242
248
  ================================================================================
243
249
  ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "flpit"
3
- version = "0.4.2.dev11"
3
+ version = "0.5.0"
4
4
  description = "Fluent LINQ for Python — flip your iterables"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -1,6 +1,6 @@
1
1
  """asyncio libraries on the flpit runtime: a pool of standard asyncio event loops.
2
2
 
3
- Provisional: the API of this module may change in 0.5. Prefer a library's sync client where one
3
+ Provisional: the API of this module may change in 0.6. Prefer a library's sync client where one
4
4
  exists (``httpx.Client``, psycopg's ``ConnectionPool``): it is written for threads and can be shared.
5
5
 
6
6
  asyncio libraries (httpx, asyncpg, redis.asyncio, aiohttp, ...) need two things: a running
@@ -468,6 +468,8 @@ class FlpIt[TItem](Iterable[TItem]):
468
468
 
469
469
  Evaluation stops as soon as the result is known.
470
470
  """
471
+ if predicate is None:
472
+ raise PredicateNoneError()
471
473
  if predicate is not _SENTINEL:
472
474
  return builtins.any(map(predicate, self))
473
475
 
@@ -489,6 +491,8 @@ class FlpIt[TItem](Iterable[TItem]):
489
491
  Returns True for an empty sequence.
490
492
  Evaluation stops at the first element that fails the predicate.
491
493
  """
494
+ if predicate is None:
495
+ raise PredicateNoneError()
492
496
  return builtins.all(map(predicate, self))
493
497
 
494
498
  def concat(self, second: Iterable[TItem]) -> "FlpIt[TItem]":
@@ -1455,7 +1459,7 @@ class FlpIt[TItem](Iterable[TItem]):
1455
1459
  if key_selector is None:
1456
1460
  raise SelectorNoneError()
1457
1461
  if element_selector is None:
1458
- raise SelectorNoneError()
1462
+ raise ElementSelectorNoneError()
1459
1463
 
1460
1464
  result: dict[Any, Any] = {}
1461
1465
  for item in self:
@@ -1836,6 +1840,9 @@ class FlpList[TItem](Collection[TItem]):
1836
1840
  return item in self.__list.data
1837
1841
 
1838
1842
  def exists(self, predicate: Callable[[TItem], bool]) -> bool:
1843
+ if predicate is None:
1844
+ raise PredicateNoneError()
1845
+
1839
1846
  return any(predicate(item) for item in self.__list.data)
1840
1847
 
1841
1848
  def find(self, predicate: Callable[[TItem], bool]) -> TItem | None:
@@ -1953,6 +1960,8 @@ class FlpList[TItem](Collection[TItem]):
1953
1960
  ) -> bool:
1954
1961
  if predicate is _SENTINEL:
1955
1962
  return len(self.__list.data) > 0
1963
+ if predicate is None:
1964
+ raise PredicateNoneError()
1956
1965
 
1957
1966
  return any(predicate(item) for item in self.__list.data)
1958
1967
 
@@ -1960,6 +1969,9 @@ class FlpList[TItem](Collection[TItem]):
1960
1969
  self,
1961
1970
  predicate: Callable[[TItem], bool],
1962
1971
  ) -> bool:
1972
+ if predicate is None:
1973
+ raise PredicateNoneError()
1974
+
1963
1975
  return all(predicate(item) for item in self.__list.data)
1964
1976
 
1965
1977
  def append(self, element: TItem) -> FlpIt[TItem]:
@@ -256,21 +256,6 @@ class _TaskMeta(type):
256
256
  _completed_task[0] = task
257
257
  return task
258
258
 
259
- @property
260
- def asyncio_interop(cls: "_TaskMeta") -> bool:
261
- """Deprecated, always True: a Task can always be awaited inside asyncio coroutines."""
262
- warnings.warn(_ASYNCIO_INTEROP_DEPRECATED, DeprecationWarning, stacklevel=2)
263
- return True
264
-
265
- @asyncio_interop.setter
266
- def asyncio_interop(cls: "_TaskMeta", enabled: bool) -> None:
267
- warnings.warn(_ASYNCIO_INTEROP_DEPRECATED + " Setting it has no effect.", DeprecationWarning, stacklevel=2)
268
-
269
-
270
- _ASYNCIO_INTEROP_DEPRECATED: Final = (
271
- "Task.asyncio_interop is deprecated and will be removed in 0.5: awaiting a Task inside "
272
- "asyncio coroutines always works, at no measurable cost to flpit awaits."
273
- )
274
259
 
275
260
 
276
261
  @dataclass(frozen=True)
@@ -317,7 +302,7 @@ class _WorkerInfo:
317
302
  # This thread's CPU-time clock, where the platform has one (Linux, BSDs; not macOS
318
303
  # or Windows): it barely moves while the thread waits, and moves while it computes.
319
304
  self.cpu_clock: int | None = None
320
- getcpuclockid = getattr(time, "pthread_getcpuclockid", None)
305
+ getcpuclockid = _thread_cpu_clock_id
321
306
  if getcpuclockid is not None:
322
307
  try:
323
308
  self.cpu_clock = getcpuclockid(threading.get_ident())
@@ -325,6 +310,12 @@ class _WorkerInfo:
325
310
  pass
326
311
 
327
312
 
313
+ # The CPU clocks the pool's gate reads (module level, so tests can stand in for another platform).
314
+ # Per-thread clocks exist on Linux and the BSDs, not on macOS or Windows.
315
+ _thread_cpu_clock_id: Callable[[int], int] | None = getattr(time, "pthread_getcpuclockid", None)
316
+ _process_time: Callable[[], float] = time.process_time
317
+
318
+
328
319
  def _cpu_capacity() -> float:
329
320
  """CPU cores Python code can use at once: 1 with the GIL, all of them without."""
330
321
  if getattr(sys, "_is_gil_enabled", lambda: True)():
@@ -3559,12 +3550,13 @@ def _spin_count() -> int:
3559
3550
  class _Stall:
3560
3551
  """The gate's view of one worker's current item: since when, and its CPU time then."""
3561
3552
 
3562
- __slots__ = ("items", "ticks", "since", "cpu")
3553
+ __slots__ = ("items", "ticks", "since", "cpu", "process_cpu")
3563
3554
 
3564
3555
  def __init__(self, info: _WorkerInfo) -> None:
3565
3556
  self.items = info.items
3566
3557
  self.ticks = 0
3567
3558
  self.since = time.monotonic()
3559
+ self.process_cpu = _process_time()
3568
3560
  self.cpu: float | None = None
3569
3561
  if info.cpu_clock is not None:
3570
3562
  try:
@@ -3628,6 +3620,10 @@ class _WorkerPool:
3628
3620
  # A stalled worker whose own CPU clock moved less than this share of the time it has been
3629
3621
  # on its item is waiting (it measures 0.000; computing ones get a share even when contended).
3630
3622
  _WAITING_CPU_SHARE: Final = 0.02
3623
+ # Without per-thread CPU clocks (macOS, Windows) the process's CPU decides, measured over at
3624
+ # least this long: Windows' process_time() moves in 15.625 ms steps, so a shorter sample reads
3625
+ # 0 while a worker computes, and one tick is too short to average out scheduling noise.
3626
+ _FALLBACK_WINDOW: Final = 0.1
3631
3627
 
3632
3628
  def __init__(
3633
3629
  self,
@@ -3885,7 +3881,7 @@ class _WorkerPool:
3885
3881
  last = self._completed
3886
3882
  starvation_due = time.monotonic() + self._starvation_interval()
3887
3883
  stalls: dict[_WorkerInfo, _Stall] = {}
3888
- cpu_then = time.process_time()
3884
+ cpu_then = _process_time()
3889
3885
  wall_then = time.monotonic()
3890
3886
  tick = self._GATE_TICK
3891
3887
  while True:
@@ -3898,7 +3894,7 @@ class _WorkerPool:
3898
3894
  if not items:
3899
3895
  break
3900
3896
  signal.set()
3901
- cpu_now = time.process_time()
3897
+ cpu_now = _process_time()
3902
3898
  now = time.monotonic()
3903
3899
  cores_used = (cpu_now - cpu_then) / max(now - wall_then, 1e-6)
3904
3900
  cpu_then, wall_then = cpu_now, now
@@ -3993,8 +3989,13 @@ class _WorkerPool:
3993
3989
  waiting += 1
3994
3990
  else:
3995
3991
  return waiting
3996
- # No per-thread CPU clocks here: decide from the CPU the process used.
3997
- if cores_used >= self._CPU_SATURATED * min(self._capacity, workers):
3992
+ # No per-thread CPU clocks here: decide from the CPU the process used while the workers
3993
+ # were stalled, over at least _FALLBACK_WINDOW. Until then they count as computing.
3994
+ oldest = min((record for _, record in stalled), key=lambda record: record.since)
3995
+ window = now - oldest.since
3996
+ if window < self._FALLBACK_WINDOW:
3997
+ return 0
3998
+ if (_process_time() - oldest.process_cpu) / window >= self._CPU_SATURATED * min(self._capacity, workers):
3998
3999
  return 0
3999
4000
  return len(stalled)
4000
4001
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes