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

Make notify thread-safe #3275

Merged
merged 4 commits into from
Sep 11, 2023
Merged

Make notify thread-safe #3275

merged 4 commits into from
Sep 11, 2023

Conversation

willmcgugan
Copy link
Collaborator

@willmcgugan willmcgugan commented Sep 11, 2023

Makes notify thread-safe. This is a convenience when working with threaded workers.

Fixes #3267


def unnotify(self, notification: Notification, refresh: bool = True) -> None:
def _unnotify(self, notification: Notification, refresh: bool = True) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

I've never used this API but this method seems like it's really useful if it's public?

Is this method how we discard notifications manually? It seems useful if notifications are longer-lived - to allow us to remove ones that are no longer relevant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem is not that self.notify() doesn't add the notification immediately. It posts a message, and returns None. That means that the user won't have a reference to the Notification object. And even if they did, it might not yet be active.

Programatically removing notifications is useful, but we will need another mechanism for that.

Copy link
Member

Choose a reason for hiding this comment

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

Not saying it's for this PR, but I think it'd be nice if notify still returned a Notification as a handle to a notification which may or may not be active. Then, if you try to unnotify a Notification that isn't active then it'd just prevent it from appearing.

Copy link
Contributor

@davep davep left a comment

Choose a reason for hiding this comment

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

One small tidy-up suggested in one of the tests; otherwise looks good and should be properly handy when debugging threaded workers!

tests/notifications/test_app_notifications.py Outdated Show resolved Hide resolved
@willmcgugan willmcgugan merged commit 9e29982 into main Sep 11, 2023
22 checks passed
@willmcgugan willmcgugan deleted the notify-thread-safe branch September 11, 2023 12:25
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.

Make notify threadsafe
3 participants