initial 'signals-actions' implementation (#6582)

https://github.com/mikf/gallery-dl/issues/6582#issuecomment-2973285775

To stop gracefully after the current file finishes processing when
Ctrl+C was pressed, or after the current post finishes processing when
SIGUSR1 was received:

{
    "signals-actions": {
        "SIGINT" : "file",
        "SIGUSR1": "post"
    }
}
This commit is contained in:
Mike Fährmann
2025-07-09 22:22:32 +02:00
parent 4dfa8a75c0
commit 0210ffcdd8
3 changed files with 34 additions and 3 deletions

View File

@@ -722,6 +722,17 @@ class CustomNone():
__repr__ = __str__
class Flags():
def __init__(self):
self.FILE = self.POST = self.CHILD = self.DOWNLOAD = None
def process(self, flag):
if flag == "terminate":
raise exception.TerminateExtraction()
raise exception.StopExtraction()
# v137.0 release of Firefox on 2025-04-01 has ordinal 739342
# 735506 == 739342 - 137 * 28
# v135.0 release of Chrome on 2025-04-01 has ordinal 739342
@@ -737,6 +748,7 @@ re = text.re
re_compile = text.re_compile
NONE = CustomNone()
FLAGS = Flags()
EPOCH = datetime.datetime(1970, 1, 1)
SECOND = datetime.timedelta(0, 1)
WINDOWS = (os.name == "nt")