Handle OS termination signals.#425
Conversation
| setUpSignals() | ||
| # Let the Python interpreter run every 500ms to handle signals. | ||
| from PyQt5.QtCore import QTimer | ||
| timer = QTimer() |
There was a problem hiding this comment.
I don't understand this. What happens if we don't have this timer? Qt's runloop doesn't let signal handling work properly?
There was a problem hiding this comment.
Exactly. Without this, Python cannot handle signals while the Qt event loop is running.
There was a problem hiding this comment.
Could we please have a comment that mentions the Qt's runloop then? The role of this piece of code is hard to grasp without the context of the PR.
|
Thanks for this PR. Although I'm not sure I understand the actual use case, it's usually a good idea to gracefully handle those things. I'll give it a try soon. |
|
Here is some context about the reason I did this fix: dupeGuru saves some stuff only during its shutdown routine. If the application is terminated via signals, the shutdown routine is not called and thus not everything is saved to disk. I created a docker container to run dupeGuru. With this fix, we can stop and restart the container and make dupeGuru shutdown gracefully. In other words, dupeGuru properly saves everything when the container is restarted/stopped. |
|
Also, here is a source where I took some inspiration: |
|
Merging, thanks! |
This pull request allows dupeGuru to terminate gracefully when receiving an OS signal.