[CLI] Don't exit()
when certain exceptions occur. (#23442)
This commit is contained in:
parent
d4654ab893
commit
0262161914
10 changed files with 55 additions and 12 deletions
|
@ -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():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue