| 25 | |
| 26 | |
| 27 | def save_main_module(file, module_name): |
| 28 | # patch provided by: Scott Schlesier - when script is run, it does not |
| 29 | # use globals from pydevd: |
| 30 | # This will prevent the pydevd script from contaminating the namespace for the script to be debugged |
| 31 | # pretend pydevd is not the main module, and |
| 32 | # convince the file to be debugged that it was loaded as main |
| 33 | m = sys.modules[module_name] = sys.modules["__main__"] |
| 34 | m.__name__ = module_name |
| 35 | loader = m.__loader__ if hasattr(m, "__loader__") else None |
| 36 | spec = spec_from_file_location("__main__", file, loader=loader) |
| 37 | m = module_from_spec(spec) |
| 38 | sys.modules["__main__"] = m |
| 39 | return m |
| 40 | |
| 41 | |
| 42 | def is_current_thread_main_thread(): |