flpit 0.4.2.dev5__py3-none-any.whl → 0.4.2.dev7__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 +81 -69
- {flpit-0.4.2.dev5.dist-info → flpit-0.4.2.dev7.dist-info}/METADATA +1 -1
- {flpit-0.4.2.dev5.dist-info → flpit-0.4.2.dev7.dist-info}/RECORD +5 -5
- {flpit-0.4.2.dev5.dist-info → flpit-0.4.2.dev7.dist-info}/WHEEL +0 -0
- {flpit-0.4.2.dev5.dist-info → flpit-0.4.2.dev7.dist-info}/licenses/LICENSE +0 -0
flpit/task.py
CHANGED
|
@@ -253,23 +253,19 @@ class _TaskMeta(type):
|
|
|
253
253
|
|
|
254
254
|
@property
|
|
255
255
|
def asyncio_interop(cls: "_TaskMeta") -> bool:
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
)
|
|
256
|
+
"""Deprecated, always True: a Task can always be awaited inside asyncio coroutines."""
|
|
257
|
+
warnings.warn(_ASYNCIO_INTEROP_DEPRECATED, DeprecationWarning, stacklevel=2)
|
|
258
|
+
return True
|
|
260
259
|
|
|
261
260
|
@asyncio_interop.setter
|
|
262
|
-
def asyncio_interop(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
else "_await_pure_flpit_task",
|
|
271
|
-
)
|
|
272
|
-
setattr(cls, "__await__", implementation)
|
|
261
|
+
def asyncio_interop(cls: "_TaskMeta", enabled: bool) -> None:
|
|
262
|
+
warnings.warn(_ASYNCIO_INTEROP_DEPRECATED + " Setting it has no effect.", DeprecationWarning, stacklevel=2)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
_ASYNCIO_INTEROP_DEPRECATED: Final = (
|
|
266
|
+
"Task.asyncio_interop is deprecated and will be removed in 0.5: awaiting a Task inside "
|
|
267
|
+
"asyncio coroutines always works, at no measurable cost to flpit awaits."
|
|
268
|
+
)
|
|
273
269
|
|
|
274
270
|
|
|
275
271
|
@dataclass(frozen=True)
|
|
@@ -763,12 +759,51 @@ class _WaitTask(_Operation):
|
|
|
763
759
|
|
|
764
760
|
def __repr__(self) -> str:
|
|
765
761
|
return (
|
|
766
|
-
"<flpit _WaitTask:
|
|
767
|
-
"
|
|
768
|
-
"flpit Task from asyncio>"
|
|
762
|
+
"<flpit _WaitTask: awaiting a flpit Task needs the flpit scheduler "
|
|
763
|
+
"or an asyncio event loop running on this thread>"
|
|
769
764
|
)
|
|
770
765
|
|
|
771
766
|
|
|
767
|
+
#: asyncio's ``_get_running_loop`` once asyncio is imported (C-accelerated; None instead of raising).
|
|
768
|
+
_asyncio_get_running_loop: Callable[[], Any] | None = None
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
def _asyncio_running_loop() -> Any:
|
|
772
|
+
"""The asyncio event loop running on this thread, or None.
|
|
773
|
+
|
|
774
|
+
Costs one C call once asyncio is imported; before that no loop can be running, and a dict
|
|
775
|
+
lookup is all it takes. Unlike ``asyncio.get_running_loop()`` it never raises, so asking on
|
|
776
|
+
a flpit worker costs about 16 ns instead of ~150-190 ns for a raised and caught exception.
|
|
777
|
+
"""
|
|
778
|
+
global _asyncio_get_running_loop
|
|
779
|
+
get_running_loop = _asyncio_get_running_loop
|
|
780
|
+
if get_running_loop is None:
|
|
781
|
+
events = sys.modules.get("asyncio.events")
|
|
782
|
+
if events is None:
|
|
783
|
+
return None
|
|
784
|
+
get_running_loop = _asyncio_get_running_loop = events._get_running_loop
|
|
785
|
+
return get_running_loop()
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
def _notify_asyncio_future(loop: Any, future: Any, completed: Task[Any]) -> None:
|
|
789
|
+
"""Continuation of a Task awaited from asyncio: resolve ``future`` on its loop."""
|
|
790
|
+
try:
|
|
791
|
+
loop.call_soon_threadsafe(_complete_asyncio_future, future, completed)
|
|
792
|
+
except RuntimeError:
|
|
793
|
+
pass # the loop is closed: nobody is left to resume
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
def _complete_asyncio_future(future: Any, completed: Task[Any]) -> None:
|
|
797
|
+
"""Runs on the asyncio loop: pass the task's outcome to the future its waiter awaits."""
|
|
798
|
+
if future.done():
|
|
799
|
+
return # the waiter was cancelled and the future with it
|
|
800
|
+
error = completed._error_to_raise()
|
|
801
|
+
if error is None:
|
|
802
|
+
future.set_result(completed._result)
|
|
803
|
+
else:
|
|
804
|
+
future.set_exception(error)
|
|
805
|
+
|
|
806
|
+
|
|
772
807
|
def _resume_from(waiter: "Task[Any]", completed: "Task[Any]") -> None:
|
|
773
808
|
"""Store the outcome of ``completed`` as the next value sent into ``waiter``.
|
|
774
809
|
|
|
@@ -1751,7 +1786,18 @@ class Task(Generic[T], metaclass=_TaskMeta):
|
|
|
1751
1786
|
return self._exception
|
|
1752
1787
|
return OperationCanceledError(f"{self.name} was cancelled")
|
|
1753
1788
|
|
|
1754
|
-
def
|
|
1789
|
+
def __await__(self) -> Generator[Any, T, T]:
|
|
1790
|
+
"""Await the task from flpit code or from an asyncio coroutine.
|
|
1791
|
+
|
|
1792
|
+
Awaited by flpit, a pending task asks one question: is an asyncio loop running on this
|
|
1793
|
+
thread? That is one C call (asyncio's ``_get_running_loop``, which returns None instead of
|
|
1794
|
+
raising), or a dict lookup while asyncio isn't imported at all (see _asyncio_running_loop);
|
|
1795
|
+
about 15 ns, within measurement noise of an await.
|
|
1796
|
+
|
|
1797
|
+
Inside asyncio, the task's completion resolves an asyncio future on that loop. Neither the
|
|
1798
|
+
frame nor the callbacks keep the task (see _release_frame): a failed task awaited from
|
|
1799
|
+
asyncio is freed by reference counting too.
|
|
1800
|
+
"""
|
|
1755
1801
|
if self._state is not _PENDING:
|
|
1756
1802
|
error = self._error_to_raise()
|
|
1757
1803
|
if error is None:
|
|
@@ -1761,59 +1807,25 @@ class Task(Generic[T], metaclass=_TaskMeta):
|
|
|
1761
1807
|
raise error
|
|
1762
1808
|
finally:
|
|
1763
1809
|
del error
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
finally:
|
|
1769
|
-
del operation
|
|
1770
|
-
|
|
1771
|
-
__await__ = _await_pure_flpit_task
|
|
1772
|
-
|
|
1773
|
-
def _await_asyncio_interop(self) -> Generator[Any, T, T]:
|
|
1774
|
-
if self._state is not _PENDING:
|
|
1775
|
-
return self._raise_or_return()
|
|
1776
|
-
|
|
1777
|
-
if "asyncio" in sys.modules:
|
|
1778
|
-
import asyncio
|
|
1779
|
-
|
|
1810
|
+
loop = _asyncio_running_loop()
|
|
1811
|
+
if loop is None:
|
|
1812
|
+
operation = _WaitTask(self._runtime, self)
|
|
1813
|
+
del self # see _release_frame
|
|
1780
1814
|
try:
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
try:
|
|
1792
|
-
result = self._raise_or_return()
|
|
1793
|
-
except BaseException as exc:
|
|
1794
|
-
future.set_exception(exc)
|
|
1795
|
-
else:
|
|
1796
|
-
future.set_result(result)
|
|
1797
|
-
|
|
1798
|
-
def notify(_: Task[Any]) -> None:
|
|
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
|
|
1815
|
+
return (yield operation)
|
|
1816
|
+
finally:
|
|
1817
|
+
del operation
|
|
1818
|
+
future = loop.create_future()
|
|
1819
|
+
# No closures: the task's continuation must stay valid after this frame is gone
|
|
1820
|
+
# (an asyncio waiter can be cancelled while the task still runs).
|
|
1821
|
+
notify = functools.partial(_notify_asyncio_future, loop, future)
|
|
1822
|
+
if not self._add_continuation(notify):
|
|
1823
|
+
notify(self)
|
|
1824
|
+
del self, notify # see _release_frame
|
|
1813
1825
|
try:
|
|
1814
|
-
return (yield
|
|
1826
|
+
return (yield from cast(Generator[Any, T, T], future.__await__()))
|
|
1815
1827
|
finally:
|
|
1816
|
-
del
|
|
1828
|
+
del future
|
|
1817
1829
|
|
|
1818
1830
|
def _error_to_raise(self) -> BaseException | None:
|
|
1819
1831
|
"""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=REvC_OWFrtJLsn6VqXmTPOZooVP5wiiw62_TCjoiBlw,168041
|
|
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.dev7.dist-info/METADATA,sha256=QDp_Lc5rZXJQneHiFMmfceGtv6t4EaRndKJLSJPlfpQ,19395
|
|
24
|
+
flpit-0.4.2.dev7.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
25
|
+
flpit-0.4.2.dev7.dist-info/licenses/LICENSE,sha256=bi5Vg_YP3Oq3jaOMQT4b7WZu0NfBcZr-nRyOExUKJrQ,1063
|
|
26
|
+
flpit-0.4.2.dev7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|