Fix unbound local when an error occurs before pool is initialized (#156750)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/156750
Approved by: https://github.com/jamesjwu
This commit is contained in:
Aaron Orenstein
2025-07-07 07:41:18 -07:00
committed by PyTorch MergeBot
parent bbb930aba2
commit edf7bb4f51

View File

@@ -1859,6 +1859,7 @@ def run_tests(
"If running on CI, add the 'keep-going' label to your PR and rerun your jobs."
)
pool = None
try:
for test in selected_tests_serial:
options_clone = copy.deepcopy(options)
@@ -1921,8 +1922,9 @@ def run_tests(
del os.environ["NUM_PARALLEL_PROCS"]
finally:
pool.terminate()
pool.join()
if pool:
pool.terminate()
pool.join()
return