From eea9c111bdc1f459e97228af4de77e6261983160 Mon Sep 17 00:00:00 2001 From: DrStrangepork Date: Fri, 7 Jul 2023 00:36:45 -0400 Subject: [PATCH 1/3] catch exception --- Lib/multiprocessing/spawn.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/multiprocessing/spawn.py b/Lib/multiprocessing/spawn.py index f1af7709104714..4fd82e83fb256e 100644 --- a/Lib/multiprocessing/spawn.py +++ b/Lib/multiprocessing/spawn.py @@ -186,14 +186,17 @@ def get_preparation_data(name): # Figure out whether to initialise main in the subprocess as a module # or through direct execution (or to leave it alone entirely) main_module = sys.modules['__main__'] - main_mod_name = getattr(main_module.__spec__, "name", None) + try: + main_mod_name = getattr(main_module.__spec__, "name", None) + except BaseException: + main_mod_name = None if main_mod_name is not None: d['init_main_from_name'] = main_mod_name elif sys.platform != 'win32' or (not WINEXE and not WINSERVICE): main_path = getattr(main_module, '__file__', None) if main_path is not None: if (not os.path.isabs(main_path) and - process.ORIGINAL_DIR is not None): + process.ORIGINAL_DIR is not None): main_path = os.path.join(process.ORIGINAL_DIR, main_path) d['init_main_from_path'] = os.path.normpath(main_path) From bc1a8c8143876a4f08e18f8aa1aded888d69ca4b Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 7 Jul 2023 04:52:02 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2023-07-07-04-52-01.gh-issue-87115.zTVSLI.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-07-07-04-52-01.gh-issue-87115.zTVSLI.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-07-07-04-52-01.gh-issue-87115.zTVSLI.rst b/Misc/NEWS.d/next/Core and Builtins/2023-07-07-04-52-01.gh-issue-87115.zTVSLI.rst new file mode 100644 index 00000000000000..3138644e2a48ca --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-07-07-04-52-01.gh-issue-87115.zTVSLI.rst @@ -0,0 +1 @@ +Fixed bug where error `AttributeError: module '__main__' has no attribute '__spec__'` occurs when using `pdb` with module `multiprocessing` From 1bd96dc6e31810e03dea9f27879b0d89e0f0cf8d Mon Sep 17 00:00:00 2001 From: DrStrangepork Date: Fri, 7 Jul 2023 18:18:22 -0400 Subject: [PATCH 3/3] AttributeError --- Lib/multiprocessing/spawn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/multiprocessing/spawn.py b/Lib/multiprocessing/spawn.py index 4fd82e83fb256e..1a8a28e4920f25 100644 --- a/Lib/multiprocessing/spawn.py +++ b/Lib/multiprocessing/spawn.py @@ -188,7 +188,7 @@ def get_preparation_data(name): main_module = sys.modules['__main__'] try: main_mod_name = getattr(main_module.__spec__, "name", None) - except BaseException: + except AttributeError: main_mod_name = None if main_mod_name is not None: d['init_main_from_name'] = main_mod_name