-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move AsyncioExecutor to separate file. #6192
Move AsyncioExecutor to separate file. #6192
Conversation
_instance = None | ||
|
||
@classmethod | ||
def instance(cls): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Add return type annotation. Also, I'd suggest adding a docstring indicating that this returns a single global AsyncioExecutor
instance.
while True: | ||
await asyncio.sleep(1) | ||
|
||
def submit(self, func: Callable[..., Awaitable[_R]], *args, **kw) -> duet.AwaitableFuture[_R]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can make the types here more precise by using ParamSpec
:
from typing_extensions import ParamSpec
...
P = ParamSpec("P")
...
def submit(self, func: Callable[P, Awaitable[R]], *args: P.args, **kwargs: P.kwargs) -> duet.AwaitableFuture[R]:
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
import duet | ||
|
||
|
||
_R = TypeVar('_R') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd probably suggest using R
here instead of _R
, since it's more common. Not actually sure why we used underscore prefixes on type variables in engine_client.py.
future = asyncio.run_coroutine_threadsafe(func(*args, **kw), self.loop) | ||
return duet.AwaitableFuture.wrap(future) | ||
|
||
_instance = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Add type annotation on this class var too.
return duet.AwaitableFuture.wrap(future) | ||
|
||
_instance = None | ||
_instance: 'AsyncioExecutor' = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should be Optional['AsyncioExecutor']
In preparation for the streaming client prototyped in #6145, AsyncioExecutor is pulled into a separate file so that it's accessible from
stream_manager.py
, a dedicated file forStreamManager
.@maffoo @wcourtney