2023-05-15 18:25:02 +02:00
|
|
|
from structio.core import run as _run
|
|
|
|
from typing import Coroutine, Any, Callable
|
|
|
|
from structio.core.kernels.fifo import FIFOKernel
|
|
|
|
from structio.core.managers.io.simple import SimpleIOManager
|
|
|
|
from structio.core.managers.signals.sigint import SigIntManager
|
|
|
|
from structio.core.time.clock import DefaultClock
|
|
|
|
from structio.core.syscalls import sleep
|
|
|
|
from structio.core.context import TaskPool, TaskScope
|
2023-05-16 11:59:01 +02:00
|
|
|
from structio.core.exceptions import Cancelled, TimedOut
|
2023-05-15 23:56:53 +02:00
|
|
|
from structio.sync import Event, Queue, MemoryChannel, Semaphore
|
2023-05-15 18:25:02 +02:00
|
|
|
from structio.core.abc import Channel, Stream, ChannelReader, ChannelWriter
|
|
|
|
|
|
|
|
|
|
|
|
def run(func: Callable[[Any, Any], Coroutine[Any, Any, Any]],
|
|
|
|
*args,
|
|
|
|
restrict_ki_to_checkpoints: bool = False,
|
|
|
|
tools: list | None = None,
|
|
|
|
):
|
|
|
|
result = _run.run(func, FIFOKernel, SimpleIOManager(), [SigIntManager()], DefaultClock(), tools,
|
|
|
|
restrict_ki_to_checkpoints, *args)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
run.__doc__ = _run.__doc__
|
|
|
|
|
|
|
|
|
|
|
|
def create_pool() -> TaskPool:
|
|
|
|
"""
|
|
|
|
Creates a new task pool
|
|
|
|
"""
|
|
|
|
|
|
|
|
return TaskPool()
|
|
|
|
|
|
|
|
|
|
|
|
def skip_after(timeout) -> TaskScope:
|
|
|
|
"""
|
|
|
|
Creates a new task scope with the
|
|
|
|
specified timeout. No error is raised
|
|
|
|
when the timeout expires
|
|
|
|
"""
|
|
|
|
|
|
|
|
result = TaskScope()
|
|
|
|
result.timeout = timeout
|
|
|
|
result.silent = True
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def with_timeout(timeout) -> TaskScope:
|
|
|
|
"""
|
|
|
|
Creates a new task scope with the
|
|
|
|
specified timeout. TimeoutError is raised
|
|
|
|
when the timeout expires
|
|
|
|
"""
|
|
|
|
|
|
|
|
result = TaskScope()
|
|
|
|
result.timeout = timeout
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def clock():
|
|
|
|
"""
|
|
|
|
Returns the current clock time of
|
|
|
|
the event loop
|
|
|
|
"""
|
|
|
|
|
|
|
|
return _run.current_loop().clock.current_time()
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = ["run",
|
|
|
|
"sleep",
|
|
|
|
"create_pool",
|
|
|
|
"clock",
|
|
|
|
"Cancelled",
|
|
|
|
"skip_after",
|
|
|
|
"with_timeout",
|
|
|
|
"Event",
|
|
|
|
"Queue",
|
|
|
|
"MemoryChannel",
|
|
|
|
"Channel",
|
|
|
|
"Stream",
|
|
|
|
"ChannelReader",
|
2023-05-15 23:56:53 +02:00
|
|
|
"ChannelWriter",
|
2023-05-16 11:59:01 +02:00
|
|
|
"Semaphore",
|
|
|
|
"TimedOut"
|
2023-05-15 18:25:02 +02:00
|
|
|
]
|