flpit 0.4.2.dev11__py3-none-any.whl → 0.4.2.dev12__py3-none-any.whl

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.
flpit/core/linq.py CHANGED
@@ -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]:
flpit/task.py CHANGED
@@ -317,7 +317,7 @@ class _WorkerInfo:
317
317
  # This thread's CPU-time clock, where the platform has one (Linux, BSDs; not macOS
318
318
  # or Windows): it barely moves while the thread waits, and moves while it computes.
319
319
  self.cpu_clock: int | None = None
320
- getcpuclockid = getattr(time, "pthread_getcpuclockid", None)
320
+ getcpuclockid = _thread_cpu_clock_id
321
321
  if getcpuclockid is not None:
322
322
  try:
323
323
  self.cpu_clock = getcpuclockid(threading.get_ident())
@@ -325,6 +325,12 @@ class _WorkerInfo:
325
325
  pass
326
326
 
327
327
 
328
+ # The CPU clocks the pool's gate reads (module level, so tests can stand in for another platform).
329
+ # Per-thread clocks exist on Linux and the BSDs, not on macOS or Windows.
330
+ _thread_cpu_clock_id: Callable[[int], int] | None = getattr(time, "pthread_getcpuclockid", None)
331
+ _process_time: Callable[[], float] = time.process_time
332
+
333
+
328
334
  def _cpu_capacity() -> float:
329
335
  """CPU cores Python code can use at once: 1 with the GIL, all of them without."""
330
336
  if getattr(sys, "_is_gil_enabled", lambda: True)():
@@ -3559,12 +3565,13 @@ def _spin_count() -> int:
3559
3565
  class _Stall:
3560
3566
  """The gate's view of one worker's current item: since when, and its CPU time then."""
3561
3567
 
3562
- __slots__ = ("items", "ticks", "since", "cpu")
3568
+ __slots__ = ("items", "ticks", "since", "cpu", "process_cpu")
3563
3569
 
3564
3570
  def __init__(self, info: _WorkerInfo) -> None:
3565
3571
  self.items = info.items
3566
3572
  self.ticks = 0
3567
3573
  self.since = time.monotonic()
3574
+ self.process_cpu = _process_time()
3568
3575
  self.cpu: float | None = None
3569
3576
  if info.cpu_clock is not None:
3570
3577
  try:
@@ -3628,6 +3635,10 @@ class _WorkerPool:
3628
3635
  # A stalled worker whose own CPU clock moved less than this share of the time it has been
3629
3636
  # on its item is waiting (it measures 0.000; computing ones get a share even when contended).
3630
3637
  _WAITING_CPU_SHARE: Final = 0.02
3638
+ # Without per-thread CPU clocks (macOS, Windows) the process's CPU decides, measured over at
3639
+ # least this long: Windows' process_time() moves in 15.625 ms steps, so a shorter sample reads
3640
+ # 0 while a worker computes, and one tick is too short to average out scheduling noise.
3641
+ _FALLBACK_WINDOW: Final = 0.1
3631
3642
 
3632
3643
  def __init__(
3633
3644
  self,
@@ -3885,7 +3896,7 @@ class _WorkerPool:
3885
3896
  last = self._completed
3886
3897
  starvation_due = time.monotonic() + self._starvation_interval()
3887
3898
  stalls: dict[_WorkerInfo, _Stall] = {}
3888
- cpu_then = time.process_time()
3899
+ cpu_then = _process_time()
3889
3900
  wall_then = time.monotonic()
3890
3901
  tick = self._GATE_TICK
3891
3902
  while True:
@@ -3898,7 +3909,7 @@ class _WorkerPool:
3898
3909
  if not items:
3899
3910
  break
3900
3911
  signal.set()
3901
- cpu_now = time.process_time()
3912
+ cpu_now = _process_time()
3902
3913
  now = time.monotonic()
3903
3914
  cores_used = (cpu_now - cpu_then) / max(now - wall_then, 1e-6)
3904
3915
  cpu_then, wall_then = cpu_now, now
@@ -3993,8 +4004,13 @@ class _WorkerPool:
3993
4004
  waiting += 1
3994
4005
  else:
3995
4006
  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):
4007
+ # No per-thread CPU clocks here: decide from the CPU the process used while the workers
4008
+ # were stalled, over at least _FALLBACK_WINDOW. Until then they count as computing.
4009
+ oldest = min((record for _, record in stalled), key=lambda record: record.since)
4010
+ window = now - oldest.since
4011
+ if window < self._FALLBACK_WINDOW:
4012
+ return 0
4013
+ if (_process_time() - oldest.process_cpu) / window >= self._CPU_SATURATED * min(self._capacity, workers):
3998
4014
  return 0
3999
4015
  return len(stalled)
4000
4016
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: flpit
3
- Version: 0.4.2.dev11
3
+ Version: 0.4.2.dev12
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
  ```
@@ -6,7 +6,7 @@ flpit/concurrent.py,sha256=HZueI_zSTX9ozwmxwrn7_HSrxT4VL3CKoDbKQRqAKLA,32211
6
6
  flpit/csv.py,sha256=QMG8AxYR32i4I_lD1KL284OXdScN6vjjgusvnqw2q-A,25862
7
7
  flpit/flp.py,sha256=WaZnrtYdxwEOJUEBv_hXg8Uwm81h8kcH64pjDh8oJhU,1527
8
8
  flpit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- flpit/task.py,sha256=yY7yMc4Yioy-5o-Fd74geU4BF0Xg7HZVF1U0ud8Ghkc,194908
9
+ flpit/task.py,sha256=yfTKlZ1boIW12JJCzPF6dArTVemfoXn8PNu_gl8EAjo,195918
10
10
  flpit/threading.py,sha256=MeWwOI2DSejmwiivSL1IVGx0US-FEsgcNRjFWdwdcSg,37236
11
11
  flpit/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  flpit/core/_grouping.py,sha256=QZNdNqXx4fcRsnun4nwkGKnst63Y10Q-rYBevof7Abw,954
@@ -16,12 +16,12 @@ flpit/core/_lookup.py,sha256=v_FC9anm6OpbQqj3DmNwOW4ppxDZY9VY5MybAvsHJsk,1641
16
16
  flpit/core/_zip.py,sha256=lz5cbHcVV12UNyaOtrUd5jz-v_XI5xEp24KbnhAQZq8,259
17
17
  flpit/core/async_linq.py,sha256=OlqpZJQASJuzoaPM2Mg6ejMR8rzeU53oBiFtas_ey4k,81749
18
18
  flpit/core/comparers.py,sha256=XH3OuTHqhcc3of8dsMtbyggv1EuL6qZBOwiB3YEaKvQ,3030
19
- flpit/core/linq.py,sha256=UInHjKiNWF-H4eDJLFCHqa-nWNHk30qc0EKBwrCGxZY,90077
19
+ flpit/core/linq.py,sha256=Mk3nzcCLDgwfCGoiFoxtZNuudb-hH72c8aubF64jgzg,90431
20
20
  flpit/json/__init__.py,sha256=7U7-KaxLbQybqmNTqDf4U54Njhac2ep5gxPEaavR7hA,4625
21
21
  flpit/json/_core.py,sha256=IhLM116xW4jI4gg3-QmRGptVr5pHRY7X7aicm8TmO3Y,13445
22
22
  flpit/json/_msgspec.py,sha256=RJKHXT3928G-E7JKn8VwGf__FCeNB4OrJzVyQ6W5uxY,21682
23
23
  flpit/json/_native.py,sha256=AmfJZbT8vR67a6To1zUBG70oa0xWCPEqjUmQUnA99-0,39981
24
- flpit-0.4.2.dev11.dist-info/METADATA,sha256=4G6sMsfkULZzTuxyNUOhtd6mJZaSSOdR7ePCvucsRQA,19396
25
- flpit-0.4.2.dev11.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
26
- flpit-0.4.2.dev11.dist-info/licenses/LICENSE,sha256=bi5Vg_YP3Oq3jaOMQT4b7WZu0NfBcZr-nRyOExUKJrQ,1063
27
- flpit-0.4.2.dev11.dist-info/RECORD,,
24
+ flpit-0.4.2.dev12.dist-info/METADATA,sha256=swRkw5gKuQMjWgRUtlOWd9-bmgl4wVIlrieBU6uTcEw,19930
25
+ flpit-0.4.2.dev12.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
26
+ flpit-0.4.2.dev12.dist-info/licenses/LICENSE,sha256=bi5Vg_YP3Oq3jaOMQT4b7WZu0NfBcZr-nRyOExUKJrQ,1063
27
+ flpit-0.4.2.dev12.dist-info/RECORD,,