flexexecutor 0.0.13__tar.gz → 0.0.14__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.
- {flexexecutor-0.0.13 → flexexecutor-0.0.14}/PKG-INFO +1 -1
- {flexexecutor-0.0.13 → flexexecutor-0.0.14}/flexexecutor.py +26 -9
- {flexexecutor-0.0.13 → flexexecutor-0.0.14}/pyproject.toml +7 -17
- {flexexecutor-0.0.13 → flexexecutor-0.0.14}/LICENSE +0 -0
- {flexexecutor-0.0.13 → flexexecutor-0.0.14}/README.md +0 -0
|
@@ -10,6 +10,7 @@ import asyncio
|
|
|
10
10
|
import atexit
|
|
11
11
|
import itertools
|
|
12
12
|
import queue
|
|
13
|
+
import sys
|
|
13
14
|
import types
|
|
14
15
|
from asyncio import AbstractEventLoop
|
|
15
16
|
from asyncio import Queue as AsyncQueue
|
|
@@ -21,10 +22,10 @@ from queue import Empty
|
|
|
21
22
|
from threading import Event, Lock, Semaphore, Thread
|
|
22
23
|
from time import monotonic
|
|
23
24
|
from typing import TYPE_CHECKING
|
|
24
|
-
from weakref import WeakKeyDictionary,
|
|
25
|
+
from weakref import WeakKeyDictionary, WeakSet, ref
|
|
25
26
|
|
|
26
27
|
if TYPE_CHECKING:
|
|
27
|
-
from
|
|
28
|
+
from typing import Callable, ParamSpec, TypeVar
|
|
28
29
|
|
|
29
30
|
P = ParamSpec("P")
|
|
30
31
|
T = TypeVar("T")
|
|
@@ -40,7 +41,10 @@ __all__ = (
|
|
|
40
41
|
"WorkerContext",
|
|
41
42
|
)
|
|
42
43
|
|
|
43
|
-
__version__ = "0.0.
|
|
44
|
+
__version__ = "0.0.14"
|
|
45
|
+
|
|
46
|
+
# The stdlib only added the BROKEN hook and prepare_context(**ctxkwargs) in 3.14
|
|
47
|
+
_PY314_PLUS = sys.version_info >= (3, 14)
|
|
44
48
|
|
|
45
49
|
# Type alias for async component (loop, queue) tuple
|
|
46
50
|
_AsyncComponent = tuple[AbstractEventLoop, "AsyncQueue[_AsyncWorkItem | None]"]
|
|
@@ -227,6 +231,9 @@ class ThreadPoolExecutor(_base.Executor):
|
|
|
227
231
|
on internal CPython APIs.
|
|
228
232
|
"""
|
|
229
233
|
|
|
234
|
+
if _PY314_PLUS:
|
|
235
|
+
BROKEN = BrokenThreadPool
|
|
236
|
+
|
|
230
237
|
_counter = itertools.count().__next__
|
|
231
238
|
|
|
232
239
|
@classmethod
|
|
@@ -253,6 +260,7 @@ class ThreadPoolExecutor(_base.Executor):
|
|
|
253
260
|
initializer=None,
|
|
254
261
|
initargs=(),
|
|
255
262
|
idle_timeout: float | None = 60.0,
|
|
263
|
+
**ctxkwargs,
|
|
256
264
|
):
|
|
257
265
|
"""Initializes a new ThreadPoolExecutor instance.
|
|
258
266
|
|
|
@@ -272,7 +280,13 @@ class ThreadPoolExecutor(_base.Executor):
|
|
|
272
280
|
:param idle_timeout: The maximum amount of time (in seconds) that a worker
|
|
273
281
|
thread can remain idle before it is terminated. If set to None or negative
|
|
274
282
|
value, workers will never be terminated. Defaults to 60 seconds.
|
|
283
|
+
|
|
284
|
+
:param ctxkwargs: Additional keyword arguments passed to
|
|
285
|
+
``cls.prepare_context()``. Only supported on Python 3.14+.
|
|
275
286
|
"""
|
|
287
|
+
if ctxkwargs and not _PY314_PLUS:
|
|
288
|
+
raise TypeError("ctxkwargs is only supported on Python 3.14+")
|
|
289
|
+
|
|
276
290
|
if max_workers is None:
|
|
277
291
|
max_workers = 1024
|
|
278
292
|
if max_workers <= 0:
|
|
@@ -293,7 +307,7 @@ class ThreadPoolExecutor(_base.Executor):
|
|
|
293
307
|
(
|
|
294
308
|
self._create_worker_context,
|
|
295
309
|
self._resolve_work_item_task,
|
|
296
|
-
) = type(self).prepare_context(initializer, initargs)
|
|
310
|
+
) = type(self).prepare_context(initializer, initargs, **ctxkwargs)
|
|
297
311
|
|
|
298
312
|
if idle_timeout is None or idle_timeout < 0:
|
|
299
313
|
self._idle_timeout = -1.0
|
|
@@ -312,7 +326,8 @@ class ThreadPoolExecutor(_base.Executor):
|
|
|
312
326
|
|
|
313
327
|
with self._shutdown_lock, _global_shutdown_lock:
|
|
314
328
|
if self._broken:
|
|
315
|
-
|
|
329
|
+
# BROKEN only exists on 3.14+, matching the stdlib API surface
|
|
330
|
+
raise getattr(self, "BROKEN", BrokenThreadPool)(self._broken)
|
|
316
331
|
|
|
317
332
|
if self._shutdown:
|
|
318
333
|
raise RuntimeError("cannot schedule new futures after shutdown")
|
|
@@ -376,7 +391,9 @@ class ThreadPoolExecutor(_base.Executor):
|
|
|
376
391
|
except Empty:
|
|
377
392
|
break
|
|
378
393
|
if work_item is not None:
|
|
379
|
-
work_item.future.set_exception(
|
|
394
|
+
work_item.future.set_exception(
|
|
395
|
+
getattr(self, "BROKEN", BrokenThreadPool)(self._broken)
|
|
396
|
+
)
|
|
380
397
|
|
|
381
398
|
def shutdown(self, wait: bool = True, *, cancel_futures: bool = False):
|
|
382
399
|
with self._shutdown_lock:
|
|
@@ -500,7 +517,7 @@ class _AsyncWorkItem:
|
|
|
500
517
|
except BaseException as exc:
|
|
501
518
|
self.future.set_exception(exc)
|
|
502
519
|
# Break a reference cycle with the exception 'exc'
|
|
503
|
-
self
|
|
520
|
+
del self
|
|
504
521
|
else:
|
|
505
522
|
self.future.set_result(result)
|
|
506
523
|
|
|
@@ -703,7 +720,7 @@ class AsyncPoolExecutor(_base.Executor):
|
|
|
703
720
|
raise BrokenThreadPool(self._broken)
|
|
704
721
|
assert self._comp
|
|
705
722
|
|
|
706
|
-
f = Future()
|
|
723
|
+
f = Future()
|
|
707
724
|
task = self._resolve_work_item_task(fn, args, kwargs)
|
|
708
725
|
w = _AsyncWorkItem(f, task)
|
|
709
726
|
loop, work_queue = self._comp[0]
|
|
@@ -717,7 +734,7 @@ class AsyncPoolExecutor(_base.Executor):
|
|
|
717
734
|
if self._thread_active.is_set():
|
|
718
735
|
return
|
|
719
736
|
|
|
720
|
-
def weakref_cb(_, c=self._comp):
|
|
737
|
+
def weakref_cb(_, c: list[_AsyncComponent] = self._comp):
|
|
721
738
|
if not c:
|
|
722
739
|
return
|
|
723
740
|
loop, work_queue = c[0]
|
|
@@ -24,7 +24,7 @@ requires-python = ">=3.11"
|
|
|
24
24
|
readme = "README.md"
|
|
25
25
|
dependencies = []
|
|
26
26
|
dynamic = []
|
|
27
|
-
version = "0.0.
|
|
27
|
+
version = "0.0.14"
|
|
28
28
|
|
|
29
29
|
[project.license]
|
|
30
30
|
text = "MIT"
|
|
@@ -54,14 +54,6 @@ excludes = [
|
|
|
54
54
|
source = "file"
|
|
55
55
|
path = "flexexecutor.py"
|
|
56
56
|
|
|
57
|
-
[tool.autoflake]
|
|
58
|
-
in-place = true
|
|
59
|
-
recursive = true
|
|
60
|
-
remove-all-unused-imports = true
|
|
61
|
-
ignore-init-module-imports = true
|
|
62
|
-
remove-duplicate-keys = true
|
|
63
|
-
remove-unused-variables = true
|
|
64
|
-
|
|
65
57
|
[tool.coverage.run]
|
|
66
58
|
branch = true
|
|
67
59
|
source = [
|
|
@@ -80,20 +72,19 @@ exclude_lines = [
|
|
|
80
72
|
|
|
81
73
|
[tool.ruff]
|
|
82
74
|
line-length = 88
|
|
75
|
+
target-version = "py311"
|
|
83
76
|
|
|
84
|
-
[tool.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
warn_unused_configs = true
|
|
77
|
+
[tool.ruff.lint]
|
|
78
|
+
select = [
|
|
79
|
+
"F",
|
|
80
|
+
"I",
|
|
81
|
+
]
|
|
90
82
|
|
|
91
83
|
[tool.pytest.ini_options]
|
|
92
84
|
asyncio_mode = "strict"
|
|
93
85
|
|
|
94
86
|
[dependency-groups]
|
|
95
87
|
dev = [
|
|
96
|
-
"autoflake>=2.3.1",
|
|
97
88
|
"coverage[toml]>=7.6.1",
|
|
98
89
|
"nox>=2024.4.15",
|
|
99
90
|
"pytest>=8.3.2",
|
|
@@ -102,7 +93,6 @@ dev = [
|
|
|
102
93
|
"pytest-mock>=3.14.0",
|
|
103
94
|
"pytest-timeout>=2.3.1",
|
|
104
95
|
"ruff>=0.9.10",
|
|
105
|
-
"typing-extensions>=4.12.2",
|
|
106
96
|
"ty>=0.0.1a34",
|
|
107
97
|
"python-lsp-server>=1.14.0",
|
|
108
98
|
]
|
|
File without changes
|
|
File without changes
|