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

Allow to use Observers as a context manager #1090

Open
BoboTiG opened this issue Dec 3, 2024 · 0 comments · May be fixed by #1091
Open

Allow to use Observers as a context manager #1090

BoboTiG opened this issue Dec 3, 2024 · 0 comments · May be fixed by #1091

Comments

@BoboTiG
Copy link
Collaborator

BoboTiG commented Dec 3, 2024

This piece of code, taken from the documentation, could be less verbose using a context manager.

Current code:

observer.start()
try:
    while True:
        time.sleep(1)
finally:
    observer.stop()
    observer.join()

Proposition:

with observer:
    while True:
        time.sleep(1)

Both codes will remain valid, of course.

@BoboTiG BoboTiG changed the title All to use Observers as a context manager Allow to use Observers as a context manager Dec 3, 2024
@alexprabhat99 alexprabhat99 linked a pull request Dec 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant