From 07db110add161c50b48cb7bc8e1c77f2b12b2c76 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 20 Nov 2020 18:53:27 +1100 Subject: Fix T82493: PyDoc generation throws exception on exit Since add-ons now unregister on exit (as of fa566157a5c351775d082b05b180c630665b4afc) clearing functions in `bpy.app.handlers` caused an error on exit. Resolve by restoring handlers before exiting. --- doc/python_api/sphinx_doc_gen.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py index 3b5d16f2233..b148f4c6a46 100644 --- a/doc/python_api/sphinx_doc_gen.py +++ b/doc/python_api/sphinx_doc_gen.py @@ -2188,9 +2188,20 @@ def setup_blender(): # Remove handlers since the functions get included # in the doc-string and don't have meaningful names. - for ls in bpy.app.handlers: - if isinstance(ls, list): - ls.clear() + lists_to_restore = [] + for var in bpy.app.handlers: + if isinstance(var, list): + lists_to_restore.append((var[:], var)) + var.clear() + + return { + "lists_to_restore": lists_to_restore, + } + + +def teardown_blender(setup_data): + for var_src, var_dst in setup_data["lists_to_restore"]: + var_dst[:] = var_src def main(): @@ -2199,7 +2210,7 @@ def main(): setup_monkey_patch() # Perform changes to Blender it's self. - setup_blender() + setup_data = setup_blender() # eventually, create the dirs for dir_path in [ARGS.output_dir, SPHINX_IN]: @@ -2305,6 +2316,8 @@ def main(): shutil.copy(os.path.join(SPHINX_OUT_PDF, "contents.pdf"), os.path.join(REFERENCE_PATH, BLENDER_PDF_FILENAME)) + teardown_blender(setup_data) + sys.exit() -- cgit v1.2.3