flpit 0.4.2.dev2__py3-none-any.whl → 0.4.2.dev4__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/task.py +49 -4
- {flpit-0.4.2.dev2.dist-info → flpit-0.4.2.dev4.dist-info}/METADATA +1 -1
- {flpit-0.4.2.dev2.dist-info → flpit-0.4.2.dev4.dist-info}/RECORD +5 -5
- {flpit-0.4.2.dev2.dist-info → flpit-0.4.2.dev4.dist-info}/WHEEL +0 -0
- {flpit-0.4.2.dev2.dist-info → flpit-0.4.2.dev4.dist-info}/licenses/LICENSE +0 -0
flpit/task.py
CHANGED
|
@@ -401,6 +401,7 @@ class _TimerQueue:
|
|
|
401
401
|
_thread_state.internal = True
|
|
402
402
|
condition = self._condition
|
|
403
403
|
due: list[Callable[[], Any]] = []
|
|
404
|
+
park = cast(float, _park_interval(self._MAX_WAIT))
|
|
404
405
|
while True:
|
|
405
406
|
with condition:
|
|
406
407
|
while True:
|
|
@@ -421,9 +422,9 @@ class _TimerQueue:
|
|
|
421
422
|
if due:
|
|
422
423
|
break
|
|
423
424
|
if heap:
|
|
424
|
-
condition.wait(min(heap[0][0] - now,
|
|
425
|
+
condition.wait(min(heap[0][0] - now, park))
|
|
425
426
|
else:
|
|
426
|
-
condition.wait()
|
|
427
|
+
condition.wait(_park_interval(None))
|
|
427
428
|
for callback in due:
|
|
428
429
|
try:
|
|
429
430
|
callback()
|
|
@@ -856,6 +857,12 @@ class Task(Generic[T], metaclass=_TaskMeta):
|
|
|
856
857
|
self._lock = threading.Lock()
|
|
857
858
|
self._state: str = _PENDING
|
|
858
859
|
# Promise-style tasks never run code and need no execution context.
|
|
860
|
+
# The context holds this task as the current task, so the two form a
|
|
861
|
+
# reference cycle. Every path on which the task's code has finished
|
|
862
|
+
# drops the context: otherwise a finished task, its result and every
|
|
863
|
+
# AsyncLocal value set inside it would only be freed by the cyclic
|
|
864
|
+
# garbage collector. (A failed task still is: its exception's traceback
|
|
865
|
+
# reaches the runtime frames that ran it, as with any stored exception.)
|
|
859
866
|
self._execution_context: Context | None = (
|
|
860
867
|
copy_context() if capture_context else None
|
|
861
868
|
)
|
|
@@ -1658,12 +1665,15 @@ class Task(Generic[T], metaclass=_TaskMeta):
|
|
|
1658
1665
|
_notify_context_exit(context)
|
|
1659
1666
|
except StopIteration as stop:
|
|
1660
1667
|
self._finish(_SUCCEEDED, result=stop.value)
|
|
1668
|
+
self._execution_context = None # break the cycle with the context
|
|
1661
1669
|
return
|
|
1662
1670
|
except OperationCanceledError as cancellation:
|
|
1663
1671
|
self._finish(_CANCELLED, exception=cancellation)
|
|
1672
|
+
self._execution_context = None # break the cycle with the context
|
|
1664
1673
|
return
|
|
1665
1674
|
except BaseException as failure:
|
|
1666
1675
|
self._finish(_FAILED, exception=failure)
|
|
1676
|
+
self._execution_context = None # break the cycle with the context
|
|
1667
1677
|
return
|
|
1668
1678
|
|
|
1669
1679
|
# The first real suspension (or an await that _suspend resolves at once).
|
|
@@ -1919,14 +1929,17 @@ class Task(Generic[T], metaclass=_TaskMeta):
|
|
|
1919
1929
|
coroutine = _await_any(value)
|
|
1920
1930
|
else:
|
|
1921
1931
|
self._finish(_SUCCEEDED, result=value)
|
|
1932
|
+
self._execution_context = None # break the cycle with the context
|
|
1922
1933
|
return
|
|
1923
1934
|
except OperationCanceledError as error:
|
|
1924
1935
|
state.tail = True
|
|
1925
1936
|
self._finish(_CANCELLED, exception=error)
|
|
1937
|
+
self._execution_context = None # break the cycle with the context
|
|
1926
1938
|
return
|
|
1927
1939
|
except BaseException as error:
|
|
1928
1940
|
state.tail = True
|
|
1929
1941
|
self._finish(_FAILED, exception=error)
|
|
1942
|
+
self._execution_context = None # break the cycle with the context
|
|
1930
1943
|
return
|
|
1931
1944
|
|
|
1932
1945
|
self._coroutine = coroutine
|
|
@@ -1994,16 +2007,19 @@ class Task(Generic[T], metaclass=_TaskMeta):
|
|
|
1994
2007
|
state.tail = True
|
|
1995
2008
|
self._coroutine = None
|
|
1996
2009
|
self._finish(_SUCCEEDED, result=stop.value)
|
|
2010
|
+
self._execution_context = None # break the cycle with the context
|
|
1997
2011
|
return
|
|
1998
2012
|
except OperationCanceledError as cancellation:
|
|
1999
2013
|
state.tail = True
|
|
2000
2014
|
self._coroutine = None
|
|
2001
2015
|
self._finish(_CANCELLED, exception=cancellation)
|
|
2016
|
+
self._execution_context = None # break the cycle with the context
|
|
2002
2017
|
return
|
|
2003
2018
|
except BaseException as failure:
|
|
2004
2019
|
state.tail = True
|
|
2005
2020
|
self._coroutine = None
|
|
2006
2021
|
self._finish(_FAILED, exception=failure)
|
|
2022
|
+
self._execution_context = None # break the cycle with the context
|
|
2007
2023
|
return
|
|
2008
2024
|
|
|
2009
2025
|
state.tail = True
|
|
@@ -2960,8 +2976,9 @@ class _IOReactor:
|
|
|
2960
2976
|
commands = self._commands
|
|
2961
2977
|
failure: BaseException | None = None
|
|
2962
2978
|
try:
|
|
2979
|
+
park = _park_interval(None)
|
|
2963
2980
|
while not self._closing:
|
|
2964
|
-
for key, mask in selector.select(
|
|
2981
|
+
for key, mask in selector.select(park):
|
|
2965
2982
|
if key.data is _WAKE:
|
|
2966
2983
|
try:
|
|
2967
2984
|
while reader.recv(4096):
|
|
@@ -3017,6 +3034,27 @@ class _IOReactor:
|
|
|
3017
3034
|
return not thread.is_alive()
|
|
3018
3035
|
|
|
3019
3036
|
|
|
3037
|
+
def _park_interval(longest: float | None) -> float | None:
|
|
3038
|
+
"""How long a runtime thread may block in one go while it has nothing to do.
|
|
3039
|
+
|
|
3040
|
+
On free-threaded builds an object is freed by the thread that created it: when
|
|
3041
|
+
another thread drops the last reference, the object is queued to its creator,
|
|
3042
|
+
which frees it the next time it runs Python code. A thread blocked for a long
|
|
3043
|
+
time would keep such objects (and everything they reference) alive. So there,
|
|
3044
|
+
idle threads wake up regularly. With the GIL, objects are freed at once and
|
|
3045
|
+
``longest`` is kept.
|
|
3046
|
+
"""
|
|
3047
|
+
gil_enabled = getattr(sys, "_is_gil_enabled", None)
|
|
3048
|
+
if gil_enabled is None or gil_enabled():
|
|
3049
|
+
return longest
|
|
3050
|
+
return _FREE_THREADED_PARK if longest is None else min(longest, _FREE_THREADED_PARK)
|
|
3051
|
+
|
|
3052
|
+
|
|
3053
|
+
# Free-threaded builds: the longest an idle runtime thread blocks without running
|
|
3054
|
+
# Python code (see _park_interval). Each wake-up costs a few microseconds.
|
|
3055
|
+
_FREE_THREADED_PARK: Final = 0.5
|
|
3056
|
+
|
|
3057
|
+
|
|
3020
3058
|
def _spin_count() -> int:
|
|
3021
3059
|
"""How long an idle worker polls for work before it parks.
|
|
3022
3060
|
|
|
@@ -3167,6 +3205,7 @@ class _WorkerPool:
|
|
|
3167
3205
|
parker.acquire()
|
|
3168
3206
|
searching = True # whoever started this thread counted it as such
|
|
3169
3207
|
counted = True
|
|
3208
|
+
park = cast(float, _park_interval(self._IDLE_TIMEOUT))
|
|
3170
3209
|
try:
|
|
3171
3210
|
while True:
|
|
3172
3211
|
item = state.slot
|
|
@@ -3222,7 +3261,13 @@ class _WorkerPool:
|
|
|
3222
3261
|
searching = True
|
|
3223
3262
|
continue
|
|
3224
3263
|
|
|
3225
|
-
|
|
3264
|
+
idle_since = time.monotonic()
|
|
3265
|
+
while not parker.acquire(timeout=park):
|
|
3266
|
+
# Waking up ran Python code: objects this thread
|
|
3267
|
+
# created and others released are freed now.
|
|
3268
|
+
if time.monotonic() - idle_since < self._IDLE_TIMEOUT:
|
|
3269
|
+
continue
|
|
3270
|
+
idle_since = time.monotonic()
|
|
3226
3271
|
with lock:
|
|
3227
3272
|
if parker not in self._parked:
|
|
3228
3273
|
# A waker picked this worker just now.
|
|
@@ -5,7 +5,7 @@ flpit/concurrent.py,sha256=HZueI_zSTX9ozwmxwrn7_HSrxT4VL3CKoDbKQRqAKLA,32211
|
|
|
5
5
|
flpit/csv.py,sha256=QMG8AxYR32i4I_lD1KL284OXdScN6vjjgusvnqw2q-A,25862
|
|
6
6
|
flpit/flp.py,sha256=WaZnrtYdxwEOJUEBv_hXg8Uwm81h8kcH64pjDh8oJhU,1527
|
|
7
7
|
flpit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
flpit/task.py,sha256=
|
|
8
|
+
flpit/task.py,sha256=_rjjebmW1GLHJl5MBvFMkCOZ6NjztNg0mRPXb1qSw_Q,162098
|
|
9
9
|
flpit/threading.py,sha256=aCIgUpuTdWdkdGrW2N4LNlxhm-PQZk5iSWZ4gEIylQc,36581
|
|
10
10
|
flpit/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
11
|
flpit/core/_grouping.py,sha256=QZNdNqXx4fcRsnun4nwkGKnst63Y10Q-rYBevof7Abw,954
|
|
@@ -20,7 +20,7 @@ flpit/json/__init__.py,sha256=7U7-KaxLbQybqmNTqDf4U54Njhac2ep5gxPEaavR7hA,4625
|
|
|
20
20
|
flpit/json/_core.py,sha256=IhLM116xW4jI4gg3-QmRGptVr5pHRY7X7aicm8TmO3Y,13445
|
|
21
21
|
flpit/json/_msgspec.py,sha256=19NB98R1tftz8LYY_2QriWo9d4Syii4f7QW_s8vWL2s,20124
|
|
22
22
|
flpit/json/_native.py,sha256=E_Ro3rXTCKDpb6jicBOYU9fzOJch6ZJkLqsKJNXAsTg,39974
|
|
23
|
-
flpit-0.4.2.
|
|
24
|
-
flpit-0.4.2.
|
|
25
|
-
flpit-0.4.2.
|
|
26
|
-
flpit-0.4.2.
|
|
23
|
+
flpit-0.4.2.dev4.dist-info/METADATA,sha256=ZhkCXLfzNwYXq5xFSKcsaF6a-pzzSDGKL09PyLe0lUQ,19395
|
|
24
|
+
flpit-0.4.2.dev4.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
25
|
+
flpit-0.4.2.dev4.dist-info/licenses/LICENSE,sha256=bi5Vg_YP3Oq3jaOMQT4b7WZu0NfBcZr-nRyOExUKJrQ,1063
|
|
26
|
+
flpit-0.4.2.dev4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|