Skip to content
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

Why does the streaming context manager not call stream.end() when exiting #123

Open
artificial-aidan opened this issue Oct 1, 2020 · 2 comments

Comments

@artificial-aidan
Copy link
Contributor

In the example provided in the docs using the open() method on a stream creates a context manager that can be used to send and receive messages. One of the purposes of a context manager is to automate cleanup.

async with stub.BiDiMethod.open() as stream:
    await stream.send_request()  # needed to initiate a call
    while True:
        task = await task_queue.get()
        if task is None:
            await stream.end()
            break
        else:
            await stream.send_message(task)
            result = await stream.recv_message()
            await result_queue.add(task)

Why is the call to stream.end() necessary? Could that not be part of the stream.__aexit__() method?

@AlecZorab
Copy link

It's not obvious to me why the context manager doesn't call stream.cancel() (ie an explicit hangup, rather than just signalling that we're not going to send more data). Once we exit the context, the stream shouldn't be usable any more anyway, right?

@AlecZorab
Copy link

a flag on open to indicate that the context manager should cancel on exit could be really useful here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants