structio/structio/__init__.py

132 lines
2.7 KiB
Python
Raw Normal View History

2023-05-15 18:25:02 +02:00
from structio.core import run as _run
from structio.core.run import run
from structio.core import kernel
2024-03-18 14:59:31 +01:00
from structio.core.policies.fifo import FIFOPolicy
2023-05-15 18:25:02 +02:00
from structio.core.managers.io.simple import SimpleIOManager
from structio.core.managers.signals.sigint import SigIntManager
from structio.core.time.clock import DefaultClock
2024-03-29 15:16:05 +01:00
from structio.core.syscalls import sleep, suspend
2023-05-15 18:25:02 +02:00
from structio.core.context import TaskPool, TaskScope
2024-02-23 13:11:14 +01:00
from structio.exceptions import (
Cancelled,
TimedOut,
ResourceClosed,
ResourceBroken,
ResourceBusy,
WouldBlock,
)
from structio.core import task
from structio.core.task import Task, TaskState
2023-06-19 17:34:44 +02:00
from structio.sync import (
Event,
Queue,
MemoryChannel,
Semaphore,
Lock,
RLock,
)
2024-03-29 15:16:05 +01:00
from structio.abc import Channel, Stream, ReadableChannel, WritableChannel
from structio.io import socket
from structio.io.socket import AsyncSocket
2023-05-22 09:22:37 +02:00
from structio.io.files import (
open_file,
wrap_file,
aprint,
stdout,
stderr,
stdin,
ainput,
)
from structio.core.run import current_loop, current_task
from structio import thread, parallel
2023-05-22 09:22:37 +02:00
from structio.path import Path
2023-06-19 17:34:44 +02:00
from structio.signals import set_signal_handler, get_signal_handler
from structio.parallel import Process, ProcessLimiter
from structio import signals as _signals
from structio import util
2023-05-22 09:22:37 +02:00
2023-05-15 18:25:02 +02:00
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
"""
2023-06-28 14:16:01 +02:00
return TaskScope(timeout=timeout, silent=True)
2023-05-15 18:25:02 +02:00
def with_timeout(timeout) -> TaskScope:
"""
Creates a new task scope with the
specified timeout. TimeoutError is raised
when the timeout expires
"""
2023-06-28 14:16:01 +02:00
return TaskScope(timeout=timeout)
2023-05-15 18:25:02 +02:00
def clock():
"""
Returns the current clock time of
the event loop
"""
return _run.current_loop().clock.current_time()
2023-05-22 09:22:37 +02:00
__all__ = [
"run",
"sleep",
"create_pool",
"clock",
"Cancelled",
"skip_after",
"with_timeout",
"Event",
"Queue",
"MemoryChannel",
"Channel",
"Stream",
2024-03-29 15:16:05 +01:00
"ReadableChannel",
"WritableChannel",
2023-05-22 09:22:37 +02:00
"Semaphore",
"TimedOut",
"Task",
"TaskState",
"TaskScope",
"TaskPool",
"ResourceClosed",
"Lock",
"RLock",
"thread",
"open_file",
"wrap_file",
"aprint",
"stderr",
"stdin",
"stdout",
"ainput",
"current_loop",
"current_task",
"Path",
2023-06-19 17:34:44 +02:00
"parallel",
"get_signal_handler",
"set_signal_handler",
"util",
2023-09-04 18:35:27 +02:00
"ResourceBusy",
"ResourceBroken",
2024-02-23 13:11:14 +01:00
"WouldBlock",
"Process",
"ProcessLimiter",
"AsyncSocket",
2023-05-22 09:22:37 +02:00
]