diff --git a/Lib/multiprocessing/spawn.py b/Lib/multiprocessing/spawn.py index daac1ecc34b55e..64b07ea8f504c9 100644 --- a/Lib/multiprocessing/spawn.py +++ b/Lib/multiprocessing/spawn.py @@ -190,14 +190,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 AttributeError: + 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) 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`