1
0
Fork 0

[CLI] Don't exit() when certain exceptions occur. (#23442)

This commit is contained in:
Nick Brassel 2024-06-15 19:37:47 +10:00 committed by GitHub
parent d4654ab893
commit 0262161914
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 55 additions and 12 deletions

View file

@ -2,9 +2,30 @@
"""
import contextlib
import multiprocessing
import sys
from milc import cli
maybe_exit_should_exit = True
maybe_exit_reraise = False
# Controls whether or not early `exit()` calls should be made
def maybe_exit(rc):
if maybe_exit_should_exit:
sys.exit(rc)
if maybe_exit_reraise:
e = sys.exception()
if e:
raise e
def maybe_exit_config(should_exit: bool = True, should_reraise: bool = False):
global maybe_exit_should_exit
global maybe_exit_reraise
maybe_exit_should_exit = should_exit
maybe_exit_reraise = should_reraise
@contextlib.contextmanager
def parallelize():