mirror of
https://github.com/akuker/RASCSI.git
synced 2024-05-28 09:41:33 +00:00
52e4a92aec
* Bump black from 22.8.0 to 24.3.0 in /python/web Bumps [black](https://github.com/psf/black) from 22.8.0 to 24.3.0. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/compare/22.8.0...24.3.0) --- updated-dependencies: - dependency-name: black dependency-type: direct:development ... Signed-off-by: dependabot[bot] <support@github.com> * Github CI: Backend web test runner use python 3.9.19 * Reformat python sources with black * Docker: Bump to python 3.9-slim image for pytest * Bump pytest version to 8.1.1 * Bump more library versions, and freeze them --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Daniel Markstedt <daniel@mindani.net>
42 lines
942 B
Python
42 lines
942 B
Python
"""
|
|
Linux interrupt handling module
|
|
"""
|
|
|
|
import signal
|
|
|
|
|
|
class GracefulInterruptHandler:
|
|
"""
|
|
Class for handling Linux signal interrupts
|
|
"""
|
|
|
|
def __init__(self, signals=(signal.SIGINT, signal.SIGTERM)):
|
|
self.signals = signals
|
|
self.original_handlers = {}
|
|
self.interrupted = False
|
|
self.released = False
|
|
|
|
def __enter__(self):
|
|
for sig in self.signals:
|
|
self.original_handlers[sig] = signal.getsignal(sig)
|
|
signal.signal(sig, self.handler)
|
|
|
|
return self
|
|
|
|
def handler(self, signum, frame):
|
|
self.release()
|
|
self.interrupted = True
|
|
|
|
def __exit__(self, exception_type, exception_value, traceback):
|
|
self.release()
|
|
|
|
def release(self):
|
|
if self.released:
|
|
return False
|
|
|
|
for sig in self.signals:
|
|
signal.signal(sig, self.original_handlers[sig])
|
|
|
|
self.released = True
|
|
return True
|