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

Skip multiprocessing if no callback actions requested; Add sound param; Fix signal handling #26

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

michelcrypt4d4mus
Copy link
Contributor

Changes:

  1. If there are no callbacks requested then there is no need for multiprocessing / listening / etc.
  2. Fix the signal handling - the argument to sys.exit() is just the return code for the shell; it does not re-raise the SIGINT to call sys.exit(signal.SIGINT). Now it properly re-raises the trapped signal.
  3. Add sound parameter as per the other PR Add sound param #25

In order to implement (1) I had to move the MacOSNotification class outside of the create_notification() method so it would not be redeclared every time create_notification() is called - see my comment.

Re: (2) I'm still not really convinced that trapping SIGINT in a package is the best idea and am kind of concerned about other unforeseen side effects but at least re-raising it seems to work as the user might expect.

Feel free to cherry pick and/or request changes.

@@ -48,12 +49,13 @@ class NotificationManager(metaclass=Singleton):
"""

def __init__(self):
self._callback_queue: SimpleQueue = SimpleQueue()
self._callback_queue: SimpleQueue | None = None
self._callback_executor_event: Event = Event()
self._callback_executor_thread: CallbackExecutorThread | None = None
self._callback_listener_process: NotificationProcess | None = None
# Specify that once we stop our application, self.cleanup should run
atexit.register(self.cleanup)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Jorricks why do you need both atexit() and custom SIGINT handling that do the exact same thing (call self.cleanup())? Seems like just atexit() should be sufficient to accomplish what you are going for?

Copy link
Owner

Choose a reason for hiding this comment

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

I honestly do not recall.
I think we can indeed remove the catch_keyboard_interrupt but let's save that for another MR.

@michelcrypt4d4mus
Copy link
Contributor Author

It turns out that because the MacOSNotification class isn't getting redefined with every call to create_notification() any more forking the initial NotificationProcess was unnecessary - you only need multithreading to listen for responses, not trigger the initial notification - so i removed NotificationProcess altogether on this PR.

@Jorricks
Copy link
Owner

First of all, sorry for being so slow to respond.
Second, I went over the MR and it looks very nice and ready to merge. Please rebase it/fix the conflicts and we can get it in.

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