MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / internal_reload_code

Function internal_reload_code

_pydevd_bundle/pydevd_comm.py:605–655  ·  view source on GitHub ↗
(dbg, seq, module_name, filename)

Source from the content-addressed store, hash-verified

603
604
605def internal_reload_code(dbg, seq, module_name, filename):
606 try:
607 found_module_to_reload = False
608 if module_name is not None:
609 module_name = module_name
610 if module_name not in sys.modules:
611 if "." in module_name:
612 new_module_name = module_name.split(".")[-1]
613 if new_module_name in sys.modules:
614 module_name = new_module_name
615
616 modules_to_reload = {}
617 module = sys.modules.get(module_name)
618 if module is not None:
619 modules_to_reload[id(module)] = (module, module_name)
620
621 if filename:
622 filename = pydevd_file_utils.normcase(filename)
623 for module_name, module in sys.modules.copy().items():
624 f = getattr_checked(module, "__file__")
625 if f is not None:
626 if f.endswith((".pyc", ".pyo")):
627 f = f[:-1]
628
629 if pydevd_file_utils.normcase(f) == filename:
630 modules_to_reload[id(module)] = (module, module_name)
631
632 if not modules_to_reload:
633 if filename and module_name:
634 _send_io_message(dbg, "code reload: Unable to find module %s to reload for path: %s\n" % (module_name, filename))
635 elif filename:
636 _send_io_message(dbg, "code reload: Unable to find module to reload for path: %s\n" % (filename,))
637 elif module_name:
638 _send_io_message(dbg, "code reload: Unable to find module to reload: %s\n" % (module_name,))
639
640 else:
641 # Too much info...
642 # _send_io_message(dbg, 'code reload: This usually means you are trying to reload the __main__ module (which cannot be reloaded).\n')
643 for module, module_name in modules_to_reload.values():
644 _send_io_message(dbg, 'code reload: Start reloading module: "' + module_name + '" ... \n')
645 found_module_to_reload = True
646
647 if pydevd_reload.xreload(module):
648 _send_io_message(dbg, "code reload: reload finished\n")
649 else:
650 _send_io_message(dbg, "code reload: reload finished without applying any change\n")
651
652 cmd = dbg.cmd_factory.make_reloaded_code_message(seq, found_module_to_reload)
653 dbg.writer.add_command(cmd)
654 except:
655 pydev_log.exception("Error reloading code")
656
657
658class InternalGetThreadStack(InternalThreadCommand):

Callers

nothing calls this directly

Calls 9

getattr_checkedFunction · 0.90
_send_io_messageFunction · 0.85
itemsMethod · 0.80
copyMethod · 0.80
valuesMethod · 0.80
exceptionMethod · 0.80
getMethod · 0.45
add_commandMethod · 0.45

Tested by

no test coverage detected