diff --git a/pyproject.toml b/pyproject.toml index a7bf704..7e5e72e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ dependencies = [ "creart~=0.3.0", ] name = "graia-broadcast" -version = "0.23.2" +version = "0.23.3" description = "a highly customizable, elegantly designed event system based on asyncio" [tool.pdm.build] diff --git a/src/graia/broadcast/__init__.py b/src/graia/broadcast/__init__.py index c79c6a6..d47a4ad 100644 --- a/src/graia/broadcast/__init__.py +++ b/src/graia/broadcast/__init__.py @@ -6,8 +6,6 @@ from contextlib import asynccontextmanager from typing import Callable, Dict, Iterable, List, Optional, Set, Type, Union -from creart import it - from .builtin.defer import DeferDispatcher from .builtin.depend import DependDispatcher from .builtin.derive import DeriveDispatcher @@ -56,11 +54,7 @@ class Broadcast: _background_tasks: Set[asyncio.Task] = set() - def __init__( - self, - *, - loop: Optional[asyncio.AbstractEventLoop] = None, - ): + def __init__(self): self.default_namespace = Namespace(name="default", default=True) self.namespaces = [] self.listeners = [] @@ -69,15 +63,6 @@ def __init__( self.prelude_dispatchers = [self.decorator_interface, DependDispatcher(), DeriveDispatcher()] self.finale_dispatchers = [DeferDispatcher()] - if loop is not None: - import warnings - - warnings.warn( - "The loop argument is deprecated since BroadcastControl 0.21, and scheduled for removal in Python 0.22.", - DeprecationWarning, - stacklevel=2, - ) - @self.prelude_dispatchers.append class BroadcastBuiltinDispatcher(BaseDispatcher): @staticmethod @@ -89,18 +74,6 @@ async def catch(interface: DispatcherInterface): elif interface.annotation is DispatcherInterface: return interface - @property - def loop(self): - import warnings - - warnings.warn( - "The loop attribute is deprecated since 0.21, and scheduled for removal in 0.22.", - DeprecationWarning, - stacklevel=2, - ) - - return it(asyncio.AbstractEventLoop) - def default_listener_generator(self, event_class) -> Iterable[Listener]: return list( filter( @@ -305,7 +278,10 @@ async def param_compile( dii.ctx.reset(dii_token) def postEvent(self, event: Dispatchable, upper_event: Optional[Dispatchable] = None): - task = it(asyncio.AbstractEventLoop).create_task( + if not hasattr(self, "_loop"): + from creart import it + self._loop = it(asyncio.AbstractEventLoop) + task = self._loop.create_task( self.layered_scheduler( listener_generator=self.default_listener_generator(event.__class__), event=event, diff --git a/src/test.py b/src/test.py index aa47ef1..ebd1886 100644 --- a/src/test.py +++ b/src/test.py @@ -77,7 +77,12 @@ async def r(ster): s = time.time() # print(s) # cProfile.run("loop.run_until_complete(asyncio.gather(*tasks))") -loop.run_until_complete(asyncio.gather(*tasks)) + + +async def main(): + await asyncio.gather(*tasks) + +asyncio.run(main()) e = time.time() n1 = e - s