cddb07a176
build container image / cpu (push) Waiting to run
build container image / cuda (push) Waiting to run
build container image / rocm (push) Waiting to run
frontend tests / frontend-tests (push) Waiting to run
openapi checks / openapi-checks (push) Waiting to run
python tests / py3.12: macos-default (push) Waiting to run
python tests / py3.11: windows-cpu (push) Waiting to run
python tests / py3.12: windows-cpu (push) Waiting to run
python tests / py3.11: linux-cpu (push) Waiting to run
python tests / py3.12: linux-cpu (push) Waiting to run
typegen checks / typegen-checks (push) Waiting to run
uv lock checks / uv-lock-checks (push) Waiting to run
frontend checks / frontend-checks (push) Waiting to run
lfs checks / lfs-check (push) Waiting to run
python checks / python-checks (push) Waiting to run
python tests / py3.11: macos-default (push) Waiting to run
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
30 lines
906 B
Python
30 lines
906 B
Python
"""
|
|
This module defines a context manager `catch_sigint()` which temporarily replaces
|
|
the sigINT handler defined by the ASGI in order to allow the user to ^C the application
|
|
and shut it down immediately. This was implemented in order to allow the user to interrupt
|
|
slow model hashing during startup.
|
|
|
|
Use like this:
|
|
|
|
from invokeai.backend.util.catch_sigint import catch_sigint
|
|
with catch_sigint():
|
|
run_some_hard_to_interrupt_process()
|
|
"""
|
|
|
|
import signal
|
|
from contextlib import contextmanager
|
|
from typing import Generator
|
|
|
|
|
|
def sigint_handler(signum, frame): # type: ignore
|
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
signal.raise_signal(signal.SIGINT)
|
|
|
|
|
|
@contextmanager
|
|
def catch_sigint() -> Generator[None, None, None]:
|
|
original_handler = signal.getsignal(signal.SIGINT)
|
|
signal.signal(signal.SIGINT, sigint_handler)
|
|
yield
|
|
signal.signal(signal.SIGINT, original_handler)
|