Refactoring and initial work on multiprocessing support

This commit is contained in:
Mattia Giambirtone 2023-05-18 18:20:50 +02:00 committed by nocturn9x
parent 45d3e308d9
commit 3e49f71f00
Signed by: nocturn9x
GPG Key ID: 8270F9F467971E59
15 changed files with 39 additions and 20 deletions

View File

@ -6,11 +6,11 @@ from structio.core.managers.signals.sigint import SigIntManager
from structio.core.time.clock import DefaultClock
from structio.core.syscalls import sleep, suspend as _suspend
from structio.core.context import TaskPool, TaskScope
from structio.core.exceptions import Cancelled, TimedOut, ResourceClosed
from structio.exceptions import Cancelled, TimedOut, ResourceClosed
from structio.core import task
from structio.core.task import Task, TaskState
from structio.sync import Event, Queue, MemoryChannel, Semaphore, Lock, RLock
from structio.core.abc import Channel, Stream, ChannelReader, ChannelWriter
from structio.abc import Channel, Stream, ChannelReader, ChannelWriter
from structio import thread
from structio.io.files import open_file, wrap_file, aprint, stdout, stderr, stdin, ainput

View File

@ -1,6 +1,6 @@
from abc import abstractmethod, ABC
from structio.core.task import Task
from structio.core.exceptions import StructIOException
from structio.exceptions import StructIOException
from typing import Callable, Any, Coroutine
from types import FrameType

View File

@ -3,7 +3,7 @@ from structio.core.run import current_loop
from structio.core.task import Task
from structio.core.syscalls import suspend, checkpoint
from typing import Callable, Coroutine, Any
from structio.core.exceptions import Cancelled, StructIOException
from structio.exceptions import Cancelled, StructIOException
class TaskScope:

View File

@ -1,12 +1,12 @@
import traceback
import warnings
from types import FrameType
from structio.core.abc import BaseKernel, BaseClock, BaseDebugger, BaseIOManager, SignalManager
from structio.abc import BaseKernel, BaseClock, BaseDebugger, BaseIOManager, SignalManager
from structio.core.context import TaskPool, TaskScope
from structio.core.task import Task, TaskState
from structio.util.ki import CTRLC_PROTECTION_ENABLED
from structio.core.time.queue import TimeQueue
from structio.core.exceptions import StructIOException, Cancelled, TimedOut
from structio.exceptions import StructIOException, Cancelled, TimedOut
from collections import deque
from typing import Callable, Coroutine, Any
from functools import partial

View File

@ -1,8 +1,7 @@
from collections import defaultdict
from structio.core.abc import BaseIOManager, AsyncResource, BaseKernel
from structio.abc import BaseIOManager, AsyncResource, BaseKernel
from structio.core.context import Task
from structio.core.run import current_loop, current_task
import socket
import select

View File

@ -1,4 +1,4 @@
from structio.core.abc import SignalManager
from structio.abc import SignalManager
from types import FrameType
from structio.util.ki import currently_protected
from structio.core.run import current_loop

View File

@ -1,8 +1,8 @@
import inspect
import functools
from threading import local
from structio.core.abc import BaseKernel, BaseDebugger, BaseClock, SignalManager, BaseIOManager
from structio.core.exceptions import StructIOException
from structio.abc import BaseKernel, BaseDebugger, BaseClock, SignalManager, BaseIOManager
from structio.exceptions import StructIOException
from structio.core.task import Task
from typing import Callable, Any, Coroutine

View File

@ -1,6 +1,6 @@
import random
from timeit import default_timer
from structio.core.abc import BaseClock
from structio.abc import BaseClock
class DefaultClock(BaseClock):

View File

@ -1,6 +1,6 @@
from typing import Any
from structio.core.task import Task, TaskState
from structio.core.abc import BaseClock
from structio.abc import BaseClock
from heapq import heappush, heappop, heapify

View File

@ -1,4 +1,4 @@
from structio.core.abc import BaseDebugger
from structio.abc import BaseDebugger
class SimpleDebugger(BaseDebugger):

View File

@ -2,7 +2,7 @@ import io
import sys
import structio
from functools import partial
from structio.core.abc import AsyncResource
from structio.abc import AsyncResource
from structio.core.syscalls import check_cancelled
# Stolen from Trio

21
structio/parallel.py Normal file
View File

@ -0,0 +1,21 @@
# Module inspired by subprocess which allows for asynchronous
# multiprocessing
from dataclasses import dataclass, field
from structio.abc import StreamWriter, StreamReader
@dataclass
class Process:
"""
An asynchronous process
"""
args: str | list
pid: int
stdin: StreamWriter | None = field(default=None)
stdout: StreamReader | None = field(default=None)
stderr: StreamReader | None = field(default=None)
returncode: int | None = field(default=None)

View File

@ -1,8 +1,8 @@
# Task synchronization primitives
from structio.core.syscalls import suspend, checkpoint
from structio.core.exceptions import ResourceClosed
from structio.exceptions import ResourceClosed
from structio.core.run import current_task, current_loop
from structio.core.abc import ChannelReader, ChannelWriter, Channel
from structio.abc import ChannelReader, ChannelWriter, Channel
from structio.util.ki import enable_ki_protection
from structio.core.task import Task
from collections import deque

View File

@ -8,11 +8,10 @@ import structio
from structio.sync import Event, Semaphore, Queue
from structio.util.ki import enable_ki_protection
from structio.core.syscalls import checkpoint
from structio.core.abc import BaseKernel
from structio.abc import BaseKernel
from structio.core.run import current_loop
from typing import Callable, Any, Coroutine
from structio.core.exceptions import StructIOException, TimedOut, Cancelled
from structio.exceptions import StructIOException
_storage = threading.local()
# Max number of concurrent threads that can