diff --git a/torch_xla/__init__.py b/torch_xla/__init__.py index de0bdea23a0..d9e915837fd 100644 --- a/torch_xla/__init__.py +++ b/torch_xla/__init__.py @@ -158,7 +158,7 @@ def _prepare_to_exit(): # Due to https://bugs.python.org/issue27035, simply raising an exception in the atexit callback does not set the exit code correctly. That is why we need to set the exit code explicitly. # Using `exit(1)` does not set a correct exit code because it is useful for the interactive interpreter shell and should not be used in programs and it works by raising an exception. (https://docs.python.org/3/library/constants.html#exit) # sys.exit(1) does not set a correct exit code because it also raises an exception. - exit(1) + os._exit(1) def _init_xla_lazy_backend():