Reformat with black

This commit is contained in:
Mattia Giambirtone 2024-02-23 13:11:14 +01:00
parent 52a09307ae
commit e1485d9317
Signed by: nocturn9x
GPG Key ID: 8270F9F467971E59
7 changed files with 25 additions and 8 deletions

View File

@ -6,7 +6,14 @@ from structio.core.managers.signals.sigint import SigIntManager
from structio.core.time.clock import DefaultClock from structio.core.time.clock import DefaultClock
from structio.core.syscalls import sleep, suspend as _suspend from structio.core.syscalls import sleep, suspend as _suspend
from structio.core.context import TaskPool, TaskScope from structio.core.context import TaskPool, TaskScope
from structio.exceptions import Cancelled, TimedOut, ResourceClosed, ResourceBroken, ResourceBusy, WouldBlock from structio.exceptions import (
Cancelled,
TimedOut,
ResourceClosed,
ResourceBroken,
ResourceBusy,
WouldBlock,
)
from structio.core import task from structio.core import task
from structio.core.task import Task, TaskState from structio.core.task import Task, TaskState
from structio.sync import ( from structio.sync import (
@ -167,5 +174,5 @@ __all__ = [
"util", "util",
"ResourceBusy", "ResourceBusy",
"ResourceBroken", "ResourceBroken",
"WouldBlock" "WouldBlock",
] ]

View File

@ -260,7 +260,6 @@ class FIFOKernel(BaseKernel):
self.throw(scope.owner, error) self.throw(scope.owner, error)
self.reschedule(scope.owner) self.reschedule(scope.owner)
def wakeup(self): def wakeup(self):
while ( while (
self.paused self.paused

View File

@ -80,7 +80,7 @@ class AsyncFile(AsyncResource):
async def readall(self): async def readall(self):
chunks = [] chunks = []
maxread = 65536 maxread = 65536
sep = '' if hasattr(self._file, 'encoding') else b'' sep = "" if hasattr(self._file, "encoding") else b""
while True: while True:
chunk = await self.read(maxread) chunk = await self.read(maxread)
if not chunk: if not chunk:

View File

@ -7,6 +7,7 @@ import platform
import subprocess import subprocess
from subprocess import CalledProcessError, CompletedProcess, DEVNULL, PIPE from subprocess import CalledProcessError, CompletedProcess, DEVNULL, PIPE
from structio.io import FileStream from structio.io import FileStream
if platform.system() == "Windows": if platform.system() == "Windows":
# Windows doesn't really support non-blocking file # Windows doesn't really support non-blocking file
# descriptors (except sockets), so we just use threads # descriptors (except sockets), so we just use threads

View File

@ -53,7 +53,9 @@ class Event:
""" """
if self.is_set(): if self.is_set():
raise RuntimeError("this event has already been set: create a new Event object instead") raise RuntimeError(
"this event has already been set: create a new Event object instead"
)
self._set = True self._set = True
for waiter in self._tasks: for waiter in self._tasks:
current_loop().reschedule(waiter) current_loop().reschedule(waiter)

View File

@ -202,7 +202,6 @@ async def _coroutine_request_handler(
coroutines: AsyncThreadQueue, coroutines: AsyncThreadQueue,
results: AsyncThreadQueue, results: AsyncThreadQueue,
reader: "structio.socket.AsyncSocket", reader: "structio.socket.AsyncSocket",
): ):
""" """
Runs coroutines on behalf of a thread spawned by structio and Runs coroutines on behalf of a thread spawned by structio and
@ -300,7 +299,16 @@ async def run_in_worker(
# Start the worker thread # Start the worker thread
threading.Thread( threading.Thread(
target=_threaded_runner, target=_threaded_runner,
args=(sync_func, current_loop(), rq, rsq, terminate, wakeup, wakeup2, *args), args=(
sync_func,
current_loop(),
rq,
rsq,
terminate,
wakeup,
wakeup2,
*args,
),
name=f"structio-worker-thread-{worker_id}", name=f"structio-worker-thread-{worker_id}",
# We start cancellable threads in daemonic mode so that # We start cancellable threads in daemonic mode so that
# the main thread doesn't get stuck waiting on them forever # the main thread doesn't get stuck waiting on them forever