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

Add Python Cancellation Example #19465

Merged
merged 32 commits into from
Aug 2, 2019
Merged

Conversation

gnossen
Copy link
Contributor

@gnossen gnossen commented Jun 25, 2019

Related: #19464

@gnossen gnossen added area/documentation lang/Python release notes: yes Indicates if PR needs to be in release notes labels Jun 25, 2019
@gnossen gnossen requested a review from lidizheng June 25, 2019 21:26
Copy link
Contributor

@lidizheng lidizheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My major concern is about the complexity overhead of the design. It's a great real-world usage, but it might be overkill for a demonstration of API usage.

Also, since many painful workaround is introduced by #19464, do you think you have some extra time to inspect the root cause?

examples/python/cancellation/client.py Outdated Show resolved Hide resolved
examples/python/cancellation/hash_name.proto Show resolved Hide resolved
examples/python/cancellation/BUILD.bazel Show resolved Hide resolved
examples/python/cancellation/README.md Show resolved Hide resolved
completed.

In the example, we use this interface to cancel our in-progress RPC when the
user interrupts the process with ctrl-c.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signal mechanism is not a necessary step for cancellation. I think a simple future.cancel() is capable of convey the idea of cancelling an unary request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline. If you have a better way to motivate why you would cancel on the client side, I'm more than happy to give it a shot.

```

It's also important that you not block indefinitely on the RPC. Otherwise, the
signal handler will never have a chance to run.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is specific to our own implementation... Ideally, we should get rid of this bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. And I have added a TODO in the example to get rid of the workaround once the bug has been fixed. But until it has, this is the only way that this can be accomplished using our library.

examples/python/cancellation/README.md Outdated Show resolved Hide resolved
propagate a timeout to Python generators. As a result, simply iterating over the
results of the RPC can block indefinitely and the signal handler may never run.
Instead, we iterate over the generator on another thread and retrieve the
results on the main thread with a synchronized `Queue`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, this is a workaround for our implementation defect. It's not that ideal to recommend it to our users...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree it would be better to fix the bug. But until then, a workaround is the next best thing. This is an example. It can always be changed once our library supports a simpler workflow.

@gnossen
Copy link
Contributor Author

gnossen commented Jun 26, 2019

@lidizheng I've made changes to address some of your concerns. I'm looking into fixing the bug that necessitated the workarounds, but in the meantime could you PTALA at the other bits that I've changed since your last review?

Copy link
Contributor

@lidizheng lidizheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly about the algorithm details. I will review the periodical check separately.

examples/python/cancellation/server.py Show resolved Hide resolved
examples/python/cancellation/search.py Show resolved Hide resolved
examples/python/cancellation/search.py Show resolved Hide resolved
examples/python/cancellation/search.py Outdated Show resolved Hide resolved
examples/python/cancellation/search.py Show resolved Hide resolved
@gnossen
Copy link
Contributor Author

gnossen commented Jul 8, 2019

@lidizheng PTALA

@gnossen gnossen merged commit b88a227 into grpc:master Aug 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/documentation lang/Python release notes: yes Indicates if PR needs to be in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants