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

Avoid signal handling reentrancy issues #1650

Merged
merged 1 commit into from
May 3, 2024

Conversation

RobinJadoul
Copy link
Contributor

If e.g. two SIGUSR1 signals arrive at almost the same time, it can be that the first one hasn't finished refreshing the UI yet when the second one needs to be handled, leading to a generator being executed twice, which python doesn't like.
We try to avoid this by scheduling the actual handling logic as a coroutine on the currently running event loop.
This has the advantage that the signal handler now has full access to any async functions or synchronization primitives.

As long as the event loop is single-threaded, the current version should avoid this particular crash as the refreshing logic is not async and hence cannot be interrupted at the event loop level.
If this were to change at some point, an asyncio.Semaphore or equivalent primitive can be easily introduced.

If e.g. two SIGUSR1 signals arrive at almost the same time,
it can be that the first one hasn't finished refreshing the UI yet when
the second one needs to be handled, leading to a generator being executed
twice, which python doesn't like.
We try to avoid this by scheduling the actual handling logic as a
coroutine on the currently running event loop.
This has the advantage that the signal handler now has full access
to any async functions or synchronization primitives.

As long as the event loop is single-threaded, the current version should
avoid this particular crash as the refreshing logic is not async and hence
cannot be interrupted at the event loop level.
If this were to change at some point, an asyncio.Semaphore or equivalent
primitive can be easily introduced.
Copy link
Owner

@pazz pazz left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@pazz pazz merged commit f9eb913 into pazz:master May 3, 2024
3 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants