Skip to content

Conversation

@verult
Copy link
Collaborator

@verult verult commented Jul 10, 2023

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 for StreamManager.

@maffoo @wcourtney

@verult verult requested a review from maffoo July 10, 2023 21:45
@verult verult requested review from a team, cduck, vtomole and wcourtney as code owners July 10, 2023 21:45
@CirqBot CirqBot added the size: M 50< lines changed <250 label Jul 10, 2023
_instance = None

@classmethod
def instance(cls):
Copy link
Contributor

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]:
Copy link
Contributor

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]:
    ...

Copy link
Collaborator Author

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')
Copy link
Contributor

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
Copy link
Contributor

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.

@verult verult requested a review from maffoo July 12, 2023 18:10
return duet.AwaitableFuture.wrap(future)

_instance = None
_instance: 'AsyncioExecutor' = None
Copy link
Contributor

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']

@verult verult enabled auto-merge (squash) July 26, 2023 18:18
@verult verult merged commit d81d07c into quantumlib:master Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: M 50< lines changed <250

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants