Skip to content

gunicorn_fractal

FractalWorker

Bases: UvicornWorker

Subclass of uvicorn workers, which also captures SIGABRT and handles it within the custom_handle_abort method.

Source code in fractal_server/gunicorn_fractal.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class FractalWorker(UvicornWorker):
    """
    Subclass of uvicorn workers, which also captures SIGABRT and handles
    it within the `custom_handle_abort` method.
    """

    def init_signals(self) -> None:
        super().init_signals()
        signal.signal(signal.SIGABRT, self.custom_handle_abort)
        logger.info(
            f"[FractalWorker.init_signals - pid={self.pid}] "
            "Set `custom_handle_abort` for SIGABRT"
        )

    def custom_handle_abort(self, sig, frame):
        """
        Custom version of `gunicorn.workers.base.Worker.handle_abort`,
        transforming SIGABRT into SIGTERM.
        """
        self.alive = False
        logger.info(
            f"[FractalWorker.custom_handle_abort - pid={self.pid}] "
            "Now send SIGTERM to process."
        )
        os.kill(self.pid, signal.SIGTERM)

custom_handle_abort(sig, frame)

Custom version of gunicorn.workers.base.Worker.handle_abort, transforming SIGABRT into SIGTERM.

Source code in fractal_server/gunicorn_fractal.py
30
31
32
33
34
35
36
37
38
39
40
def custom_handle_abort(self, sig, frame):
    """
    Custom version of `gunicorn.workers.base.Worker.handle_abort`,
    transforming SIGABRT into SIGTERM.
    """
    self.alive = False
    logger.info(
        f"[FractalWorker.custom_handle_abort - pid={self.pid}] "
        "Now send SIGTERM to process."
    )
    os.kill(self.pid, signal.SIGTERM)