Skip to content

Conversation

Ginkss
Copy link

@Ginkss Ginkss commented Oct 15, 2024

Add support for context manager. Start on entry, cancel on exit

Add support for context manager. Start on entry, cancel on exit
@ghost
Copy link

ghost commented Oct 15, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Oct 15, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

self.start()

def __exit__(self, exc_type, exc_val, exc_tb):
self.cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

this should probably join the Timer thread

Copy link
Author

Choose a reason for hiding this comment

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

Why block the main thread for a canceled timer?

Copy link
Contributor

@graingert graingert Oct 16, 2024

Choose a reason for hiding this comment

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

The main thread won't be blocked very long, it's to support use cases like:

with Timer(1, print, ("Trust me, I'm on it...",)):
    time.sleep(2)
os.fork() # all threads need to be joined before calling fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants