flpit 0.4.2.dev11__tar.gz → 0.4.2.dev12__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.
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/PKG-INFO +27 -21
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/README.md +26 -20
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/pyproject.toml +1 -1
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/core/linq.py +13 -1
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/task.py +22 -6
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/.gitignore +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/LICENSE +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flp/__init__.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/__init__.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/asyncio_bridge.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/channels.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/concurrent.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/core/__init__.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/core/_grouping.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/core/_index.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/core/_join.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/core/_lookup.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/core/_zip.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/core/async_linq.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/core/comparers.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/csv.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/flp.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/json/__init__.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/json/_core.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/json/_msgspec.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/json/_native.py +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/src/flpit/py.typed +0 -0
- {flpit-0.4.2.dev11 → flpit-0.4.2.dev12}/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.
|
|
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 |
|
|
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 |
|
|
165
|
+
| │ ├── test_max_by.py | 12 |
|
|
166
166
|
| │ ├── test_min.py | 11 |
|
|
167
|
-
| │ ├── test_min_by.py |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
235
|
-
| │ ├── test_min.py |
|
|
234
|
+
| │ ├── test_max.py | 1098 |
|
|
235
|
+
| │ ├── test_min.py | 966 |
|
|
236
236
|
| │ ├── test_of_type.py | 38 |
|
|
237
|
-
| │ ├── test_order_by.py |
|
|
238
|
-
| │ ├── test_order_descending_by.py |
|
|
237
|
+
| │ ├── test_order_by.py | 104 |
|
|
238
|
+
| │ ├── test_order_descending_by.py | 46 |
|
|
239
239
|
| │ ├── test_reverse.py | 35 |
|
|
240
|
-
| │ ├── test_select.py |
|
|
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 |
|
|
244
|
+
| │ ├── test_skip.py | 77 |
|
|
245
245
|
| │ ├── test_skip_last.py | 1221 |
|
|
246
|
-
| │ ├── test_sum.py |
|
|
247
|
-
| │ ├── test_take.py |
|
|
246
|
+
| │ ├── test_sum.py | 154 |
|
|
247
|
+
| │ ├── test_take.py | 73 |
|
|
248
248
|
| │ ├── test_take_last.py | 1221 |
|
|
249
|
-
| │ ├── test_then_by.py |
|
|
250
|
-
| │ ├── test_then_descending_by.py |
|
|
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
|
-
| │ ├──
|
|
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 |
|
|
265
|
-
| │ ├── test_task_rt_core.py |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
134
|
+
| │ ├── test_max_by.py | 12 |
|
|
135
135
|
| │ ├── test_min.py | 11 |
|
|
136
|
-
| │ ├── test_min_by.py |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
204
|
-
| │ ├── test_min.py |
|
|
203
|
+
| │ ├── test_max.py | 1098 |
|
|
204
|
+
| │ ├── test_min.py | 966 |
|
|
205
205
|
| │ ├── test_of_type.py | 38 |
|
|
206
|
-
| │ ├── test_order_by.py |
|
|
207
|
-
| │ ├── test_order_descending_by.py |
|
|
206
|
+
| │ ├── test_order_by.py | 104 |
|
|
207
|
+
| │ ├── test_order_descending_by.py | 46 |
|
|
208
208
|
| │ ├── test_reverse.py | 35 |
|
|
209
|
-
| │ ├── test_select.py |
|
|
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 |
|
|
213
|
+
| │ ├── test_skip.py | 77 |
|
|
214
214
|
| │ ├── test_skip_last.py | 1221 |
|
|
215
|
-
| │ ├── test_sum.py |
|
|
216
|
-
| │ ├── test_take.py |
|
|
215
|
+
| │ ├── test_sum.py | 154 |
|
|
216
|
+
| │ ├── test_take.py | 73 |
|
|
217
217
|
| │ ├── test_take_last.py | 1221 |
|
|
218
|
-
| │ ├── test_then_by.py |
|
|
219
|
-
| │ ├── test_then_descending_by.py |
|
|
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
|
-
| │ ├──
|
|
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 |
|
|
234
|
-
| │ ├── test_task_rt_core.py |
|
|
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 |
|
|
247
|
+
| GRAND TOTALS | 10848 |
|
|
242
248
|
================================================================================
|
|
243
249
|
```
|
|
@@ -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
|
|
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]:
|
|
@@ -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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
|
|
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
|