Skip to content

Allow to use Observers as a context manager #1090

@BoboTiG

Description

@BoboTiG

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions