More bugfixes. Exported current_loop() and current_task()
This commit is contained in:
parent
2459a7ea00
commit
6ceaec6a99
|
@ -13,6 +13,7 @@ from structio.sync import Event, Queue, MemoryChannel, Semaphore, Lock, RLock
|
||||||
from structio.abc import Channel, Stream, ChannelReader, ChannelWriter
|
from structio.abc import Channel, Stream, ChannelReader, ChannelWriter
|
||||||
from structio import thread
|
from structio import thread
|
||||||
from structio.io.files import open_file, wrap_file, aprint, stdout, stderr, stdin, ainput
|
from structio.io.files import open_file, wrap_file, aprint, stdout, stderr, stdin, ainput
|
||||||
|
from structio.core.run import current_loop, current_task
|
||||||
|
|
||||||
|
|
||||||
def run(func: Callable[[Any, Any], Coroutine[Any, Any, Any]],
|
def run(func: Callable[[Any, Any], Coroutine[Any, Any, Any]],
|
||||||
|
@ -119,5 +120,7 @@ __all__ = ["run",
|
||||||
"stderr",
|
"stderr",
|
||||||
"stdin",
|
"stdin",
|
||||||
"stdout",
|
"stdout",
|
||||||
"ainput"
|
"ainput",
|
||||||
|
"current_loop",
|
||||||
|
"current_task"
|
||||||
]
|
]
|
||||||
|
|
|
@ -138,7 +138,6 @@ class FIFOKernel(BaseKernel):
|
||||||
def reschedule(self, task: Task):
|
def reschedule(self, task: Task):
|
||||||
if task.done():
|
if task.done():
|
||||||
return
|
return
|
||||||
#print(__import__("inspect").stack()[1].function)
|
|
||||||
self.run_queue.append(task)
|
self.run_queue.append(task)
|
||||||
|
|
||||||
def check_cancelled(self):
|
def check_cancelled(self):
|
||||||
|
@ -344,7 +343,7 @@ class FIFOKernel(BaseKernel):
|
||||||
self.current_pool = pool
|
self.current_pool = pool
|
||||||
|
|
||||||
def close_pool(self, pool: TaskPool):
|
def close_pool(self, pool: TaskPool):
|
||||||
self.current_pool = self.current_pool.outer
|
self.current_pool = pool.outer
|
||||||
|
|
||||||
def suspend(self):
|
def suspend(self):
|
||||||
self.current_task.state = TaskState.PAUSED
|
self.current_task.state = TaskState.PAUSED
|
||||||
|
|
|
@ -50,7 +50,6 @@ def run(func: Callable[[Any, Any], Coroutine[Any, Any, Any]],
|
||||||
|
|
||||||
if not issubclass(kernel, BaseKernel):
|
if not issubclass(kernel, BaseKernel):
|
||||||
raise TypeError(f"kernel must be a subclass of structio.core.abc.BaseKernel!")
|
raise TypeError(f"kernel must be a subclass of structio.core.abc.BaseKernel!")
|
||||||
params = []
|
|
||||||
check = func
|
check = func
|
||||||
if isinstance(func, functools.partial):
|
if isinstance(func, functools.partial):
|
||||||
check = func.func
|
check = func.func
|
||||||
|
@ -61,7 +60,6 @@ def run(func: Callable[[Any, Any], Coroutine[Any, Any, Any]],
|
||||||
)
|
)
|
||||||
elif not inspect.iscoroutinefunction(check):
|
elif not inspect.iscoroutinefunction(check):
|
||||||
raise StructIOException("structio.run() requires an async function as its first argument!")
|
raise StructIOException("structio.run() requires an async function as its first argument!")
|
||||||
params.extend(args)
|
|
||||||
new_event_loop(kernel(clock=clock, restrict_ki_to_checkpoints=restrict_ki_to_checkpoints,
|
new_event_loop(kernel(clock=clock, restrict_ki_to_checkpoints=restrict_ki_to_checkpoints,
|
||||||
io_manager=io_manager, signal_managers=signal_managers,
|
io_manager=io_manager, signal_managers=signal_managers,
|
||||||
tools=tools))
|
tools=tools))
|
||||||
|
|
Loading…
Reference in New Issue