Skip to content

Conversation

@krisajenkins
Copy link

Adding with support for consumers.

Creating a consumer using a with statement:

 with Consumer(...) as c: c.subscribe(...) ...

...ensures that the consumer will be automatically closed when the block exits. There is no longer any need for a finally: close()block.

This change makes it easier for beginners and experts alike to use consumers correctly and cleanly. The fact that it's less to type is a nice bonus.

with has been a part of Python since v2.5 and is the recommended way to manage resource lifecycles.

It's declared as a function with no args (just `self`), but actually takes a second argument which it ignores. I've corrected the function signature to match the declaration.
@krisajenkins krisajenkins requested a review from a team as a code owner October 11, 2022 11:20
@CLAassistant
Copy link

CLAassistant commented Oct 11, 2022

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Kris Jenkins seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@krisajenkins krisajenkins force-pushed the consumer-with-support branch from cb0bd4b to ae2074e Compare October 11, 2022 11:52
Kris Jenkins added 2 commits October 21, 2022 16:02
Creating a consumer using a `with` statement: ```python with Consumer(...) as c: c.subscribe(...) ... ``` ...ensures that the consumer will be automatically closed when the block exits. There is no longer any need for a `finally: close()` block. This change makes it easier for beginners and experts alike to use consumers correctly and cleanly. The fact that it's less to type is a nice bonus. `with` has been a part of Python since v2.5 and is the recommended way to manage resource lifecycles.
Let's start people off on the right footing. (Note to reviewer - these changes are easier to review if you hide whitespace changes.)
@krisajenkins krisajenkins force-pushed the consumer-with-support branch from fef087a to e184321 Compare October 21, 2022 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants