Add a try: except: around loop.add_signal_handler()#1011
Add a try: except: around loop.add_signal_handler()#1011ajkavanagh wants to merge 2 commits intojuju:masterfrom ajkavanagh:add-guard-to-signal-handling
Conversation
For py 3.8, 3.9 and 3.10, the set_wakeup_fd() call fails on a background thread, due to [1], which has been fixed in py3.11. This patch simply catches the error if the python version can't do the adding of a signal handler so that the existing/previous behaviour continues. [1] python/cpython#87173 Closes-Bug: #1010
|
Hey @ajkavanagh, yeah I can see why this can be a problem off the main thread. In general, I like this solution (except maybe just catch the However, this makes me wonder whether pylibjuju installing signal handlers is correct to begin with. So, pylibjuju has two notions built-in to make it useful in general; a library, and a client (I'd like to eventually split these two in the future). Adding signal handlers makes sense from a client perspective, however, it doesn't makes sense at all from a library perspective. I'm beginning to think that it's a mistake for pylibjuju to enforce certain way of handling a signal (for projects using pylibjuju as a library). So it makes slightly more sense to remove the code that adds (and removes) the signal handlers in a connection. That'll solve your problem as well. WDYT? |
Yes, that's a reasonable point; I was essentially just copying the existing model from juju/jasyncio.py to try to keep things similar.
Well that was my first thought too. Libs generally shouldn't, I guess, be handling signals, as it ought to be something that the client-of-the-library ought to do.
Yes, I agree with you. It would probably be good to give an example in the lib docs on how to catch signals so that the client can clean up properly as well, but I'd agree that the onus should be on the user-of-the-library to be responsible for cleaning up the code. As such, please fee free to reject/close this change if you'd prefer a different approach. Thanks! |
#1014 #### Description In #1010 it's reported that running pylibjuju in an off-main thread blows up the `add_signal_handler` (for a good reason). Also per the discussion in the #1011 about signal handlers, this PR removes the code that installs signal handlers to the event loop at the connection creation. See [my comment](#1011 (comment)) in #1011 for details about reasoning. Fixes #1010
|
Based on #1014 merging, this is no longer needed. Thanks for the fix! |
For py 3.8, 3.9 and 3.10, the set_wakeup_fd() call fails on a background thread, due to [1], which has been fixed in py3.11. This patch simply catches the error if the python version can't do the adding of a signal handler so that the existing/previous behaviour continues.
[1] python/cpython#87173
Closes-Bug: #1010
Description
Closes-Bug: #1010
QA Steps
<Commands / tests / steps to run to verify that the change works:>
All CI tests need to pass.