mirror of https://github.com/nocturn9x/giambio.git
Fixed mistake from rebase
This commit is contained in:
parent
d408cffa87
commit
60df2f059a
|
@ -53,7 +53,7 @@ class TaskManager:
|
||||||
self._proper_init = False
|
self._proper_init = False
|
||||||
self.enclosed_pool: Optional["giambio.context.TaskManager"] = None
|
self.enclosed_pool: Optional["giambio.context.TaskManager"] = None
|
||||||
self.raise_on_timeout: bool = raise_on_timeout
|
self.raise_on_timeout: bool = raise_on_timeout
|
||||||
self.entry_point: Optional[giambio.Task] = None
|
self.entry_point: Optional[Task] = None
|
||||||
|
|
||||||
async def spawn(self, func: Callable[..., Coroutine[Any, Any, Any]], *args, **kwargs) -> "giambio.task.Task":
|
async def spawn(self, func: Callable[..., Coroutine[Any, Any, Any]], *args, **kwargs) -> "giambio.task.Task":
|
||||||
"""
|
"""
|
||||||
|
@ -66,7 +66,7 @@ class TaskManager:
|
||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
"""
|
"""
|
||||||
Implements the asynchronous context manager interface,
|
Implements the asynchronous context manager interface
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._proper_init = True
|
self._proper_init = True
|
||||||
|
|
|
@ -92,7 +92,7 @@ def create_pool():
|
||||||
Creates an async pool
|
Creates an async pool
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return TaskManager(get_event_loop().current_task)
|
return TaskManager()
|
||||||
|
|
||||||
|
|
||||||
def with_timeout(timeout: int or float):
|
def with_timeout(timeout: int or float):
|
||||||
|
@ -101,7 +101,7 @@ def with_timeout(timeout: int or float):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert timeout > 0, "The timeout must be greater than 0"
|
assert timeout > 0, "The timeout must be greater than 0"
|
||||||
mgr = TaskManager(get_event_loop().current_task, timeout, True)
|
mgr = TaskManager(timeout, True)
|
||||||
loop = get_event_loop()
|
loop = get_event_loop()
|
||||||
if loop.current_task is loop.entry_point:
|
if loop.current_task is loop.entry_point:
|
||||||
loop.current_pool = mgr
|
loop.current_pool = mgr
|
||||||
|
@ -117,7 +117,7 @@ def skip_after(timeout: int or float):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert timeout > 0, "The timeout must be greater than 0"
|
assert timeout > 0, "The timeout must be greater than 0"
|
||||||
mgr = TaskManager(get_event_loop().current_task, timeout)
|
mgr = TaskManager(timeout)
|
||||||
loop = get_event_loop()
|
loop = get_event_loop()
|
||||||
if loop.current_task is loop.entry_point:
|
if loop.current_task is loop.entry_point:
|
||||||
loop.current_pool = mgr
|
loop.current_pool = mgr
|
||||||
|
|
|
@ -67,7 +67,7 @@ async def create_task(coro: Callable[[Any, Any], Coroutine[Any, Any, Any]], pool
|
||||||
"\nWhat you wanna do, instead, is this: pool.create_task(your_func, arg1, arg2, ...)"
|
"\nWhat you wanna do, instead, is this: pool.create_task(your_func, arg1, arg2, ...)"
|
||||||
)
|
)
|
||||||
elif inspect.iscoroutinefunction(coro):
|
elif inspect.iscoroutinefunction(coro):
|
||||||
return await create_trap("create_task", coro(*args, **kwargs), pool)
|
return await create_trap("create_task", coro, pool, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
raise TypeError("coro must be a coroutine function")
|
raise TypeError("coro must be a coroutine function")
|
||||||
|
|
||||||
|
|
|
@ -71,4 +71,5 @@ if __name__ == "__main__":
|
||||||
if isinstance(error, KeyboardInterrupt):
|
if isinstance(error, KeyboardInterrupt):
|
||||||
logging.info("Ctrl+C detected, exiting")
|
logging.info("Ctrl+C detected, exiting")
|
||||||
else:
|
else:
|
||||||
|
raise
|
||||||
logging.error(f"Exiting due to a {type(error).__name__}: {error}")
|
logging.error(f"Exiting due to a {type(error).__name__}: {error}")
|
||||||
|
|
Loading…
Reference in New Issue