2023-05-15 18:25:02 +02:00
|
|
|
from structio.core import run as _run
|
2024-03-26 11:54:28 +01:00
|
|
|
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,
|
|
|
|
)
|
2023-05-16 15:48:19 +02:00
|
|
|
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
|
2023-06-06 11:31:30 +02:00
|
|
|
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,
|
|
|
|
)
|
2023-05-18 22:21:04 +02:00
|
|
|
from structio.core.run import current_loop, current_task
|
2023-06-15 16:39:08 +02:00
|
|
|
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
|
2024-03-12 16:26:48 +01:00
|
|
|
from structio.parallel import Process, ProcessLimiter
|
2023-06-19 19:10:00 +02:00
|
|
|
from structio import signals as _signals
|
2023-06-27 17:58:12 +02:00
|
|
|
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",
|
2023-06-28 14:33:50 +02:00
|
|
|
"util",
|
2023-09-04 18:35:27 +02:00
|
|
|
"ResourceBusy",
|
|
|
|
"ResourceBroken",
|
2024-02-23 13:11:14 +01:00
|
|
|
"WouldBlock",
|
2024-03-10 19:35:00 +01:00
|
|
|
"Process",
|
2024-03-12 16:26:48 +01:00
|
|
|
"ProcessLimiter",
|
2024-03-10 19:35:00 +01:00
|
|
|
"AsyncSocket",
|
2023-05-22 09:22:37 +02:00
|
|
|
]
|