flpit 0.4.2.dev5__py3-none-any.whl → 0.4.2.dev6__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 +77 -38
- {flpit-0.4.2.dev5.dist-info → flpit-0.4.2.dev6.dist-info}/METADATA +1 -1
- {flpit-0.4.2.dev5.dist-info → flpit-0.4.2.dev6.dist-info}/RECORD +5 -5
- {flpit-0.4.2.dev5.dist-info → flpit-0.4.2.dev6.dist-info}/WHEEL +0 -0
- {flpit-0.4.2.dev5.dist-info → flpit-0.4.2.dev6.dist-info}/licenses/LICENSE +0 -0
flpit/task.py
CHANGED
|
@@ -769,6 +769,46 @@ class _WaitTask(_Operation):
|
|
|
769
769
|
)
|
|
770
770
|
|
|
771
771
|
|
|
772
|
+
#: asyncio's ``_get_running_loop`` once asyncio is imported (C-accelerated; None instead of raising).
|
|
773
|
+
_asyncio_get_running_loop: Callable[[], Any] | None = None
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
def _asyncio_running_loop() -> Any:
|
|
777
|
+
"""The asyncio event loop running on this thread, or None.
|
|
778
|
+
|
|
779
|
+
Costs one C call once asyncio is imported; before that no loop can be running, and a dict
|
|
780
|
+
lookup is all it takes. Unlike ``asyncio.get_running_loop()`` it never raises, so asking on
|
|
781
|
+
a flpit worker costs about 16 ns instead of ~150-190 ns for a raised and caught exception.
|
|
782
|
+
"""
|
|
783
|
+
global _asyncio_get_running_loop
|
|
784
|
+
get_running_loop = _asyncio_get_running_loop
|
|
785
|
+
if get_running_loop is None:
|
|
786
|
+
events = sys.modules.get("asyncio.events")
|
|
787
|
+
if events is None:
|
|
788
|
+
return None
|
|
789
|
+
get_running_loop = _asyncio_get_running_loop = events._get_running_loop
|
|
790
|
+
return get_running_loop()
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
def _notify_asyncio_future(loop: Any, future: Any, completed: Task[Any]) -> None:
|
|
794
|
+
"""Continuation of a Task awaited from asyncio: resolve ``future`` on its loop."""
|
|
795
|
+
try:
|
|
796
|
+
loop.call_soon_threadsafe(_complete_asyncio_future, future, completed)
|
|
797
|
+
except RuntimeError:
|
|
798
|
+
pass # the loop is closed: nobody is left to resume
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
def _complete_asyncio_future(future: Any, completed: Task[Any]) -> None:
|
|
802
|
+
"""Runs on the asyncio loop: pass the task's outcome to the future its waiter awaits."""
|
|
803
|
+
if future.done():
|
|
804
|
+
return # the waiter was cancelled and the future with it
|
|
805
|
+
error = completed._error_to_raise()
|
|
806
|
+
if error is None:
|
|
807
|
+
future.set_result(completed._result)
|
|
808
|
+
else:
|
|
809
|
+
future.set_exception(error)
|
|
810
|
+
|
|
811
|
+
|
|
772
812
|
def _resume_from(waiter: "Task[Any]", completed: "Task[Any]") -> None:
|
|
773
813
|
"""Store the outcome of ``completed`` as the next value sent into ``waiter``.
|
|
774
814
|
|
|
@@ -1771,49 +1811,48 @@ class Task(Generic[T], metaclass=_TaskMeta):
|
|
|
1771
1811
|
__await__ = _await_pure_flpit_task
|
|
1772
1812
|
|
|
1773
1813
|
def _await_asyncio_interop(self) -> Generator[Any, T, T]:
|
|
1774
|
-
|
|
1775
|
-
return self._raise_or_return()
|
|
1814
|
+
"""``__await__`` that also works inside asyncio coroutines (``Task.asyncio_interop``).
|
|
1776
1815
|
|
|
1777
|
-
|
|
1778
|
-
|
|
1816
|
+
Awaited by flpit, it is the pure path plus one question, asked only while the task is
|
|
1817
|
+
still pending: is an asyncio loop running on this thread? That is one C call (asyncio's
|
|
1818
|
+
``_get_running_loop``, which returns None instead of raising), or a dict lookup while
|
|
1819
|
+
asyncio isn't imported at all (see _asyncio_running_loop).
|
|
1779
1820
|
|
|
1821
|
+
Inside asyncio, the task's completion resolves an asyncio future on that loop. Neither the
|
|
1822
|
+
frame nor the callbacks keep the task (see _release_frame): a failed task awaited from
|
|
1823
|
+
asyncio is freed by reference counting too.
|
|
1824
|
+
"""
|
|
1825
|
+
if self._state is not _PENDING:
|
|
1826
|
+
error = self._error_to_raise()
|
|
1827
|
+
if error is None:
|
|
1828
|
+
return cast(T, self._result)
|
|
1829
|
+
del self # see _release_frame
|
|
1780
1830
|
try:
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
try:
|
|
1800
|
-
loop.call_soon_threadsafe(complete_future)
|
|
1801
|
-
except RuntimeError:
|
|
1802
|
-
pass
|
|
1803
|
-
|
|
1804
|
-
if not self._add_continuation(notify):
|
|
1805
|
-
notify(self)
|
|
1806
|
-
|
|
1807
|
-
return (
|
|
1808
|
-
yield from cast(Generator[Any, T, T], future.__await__())
|
|
1809
|
-
)
|
|
1810
|
-
|
|
1811
|
-
operation = _WaitTask(self._runtime, self)
|
|
1812
|
-
del self # see _release_frame
|
|
1831
|
+
raise error
|
|
1832
|
+
finally:
|
|
1833
|
+
del error
|
|
1834
|
+
loop = _asyncio_running_loop()
|
|
1835
|
+
if loop is None:
|
|
1836
|
+
operation = _WaitTask(self._runtime, self)
|
|
1837
|
+
del self # see _release_frame
|
|
1838
|
+
try:
|
|
1839
|
+
return (yield operation)
|
|
1840
|
+
finally:
|
|
1841
|
+
del operation
|
|
1842
|
+
future = loop.create_future()
|
|
1843
|
+
# No closures: the task's continuation must stay valid after this frame is gone
|
|
1844
|
+
# (an asyncio waiter can be cancelled while the task still runs).
|
|
1845
|
+
notify = functools.partial(_notify_asyncio_future, loop, future)
|
|
1846
|
+
if not self._add_continuation(notify):
|
|
1847
|
+
notify(self)
|
|
1848
|
+
del self, notify # see _release_frame
|
|
1813
1849
|
try:
|
|
1814
|
-
return (yield
|
|
1850
|
+
return (yield from cast(Generator[Any, T, T], future.__await__()))
|
|
1815
1851
|
finally:
|
|
1816
|
-
del
|
|
1852
|
+
del future
|
|
1853
|
+
|
|
1854
|
+
# On by default: awaited by flpit code it costs about 0.1 µs (see _await_asyncio_interop).
|
|
1855
|
+
__await__ = _await_asyncio_interop
|
|
1817
1856
|
|
|
1818
1857
|
def _error_to_raise(self) -> BaseException | None:
|
|
1819
1858
|
"""The exception that awaiting this completed task raises; None if it succeeded.
|
|
@@ -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=8cXcevhP4fSRISypqraPjWsZRu5QMVkXocSy8jSCyOo,168663
|
|
9
9
|
flpit/threading.py,sha256=MeWwOI2DSejmwiivSL1IVGx0US-FEsgcNRjFWdwdcSg,37236
|
|
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.dev6.dist-info/METADATA,sha256=dZaLfNlJ90_M9tSAVVfcP1tULNqnrVa1PDZD4iVyzO4,19395
|
|
24
|
+
flpit-0.4.2.dev6.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
25
|
+
flpit-0.4.2.dev6.dist-info/licenses/LICENSE,sha256=bi5Vg_YP3Oq3jaOMQT4b7WZu0NfBcZr-nRyOExUKJrQ,1063
|
|
26
|
+
flpit-0.4.2.dev6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|