debugging - Python spyder debug freezes with circular importing -
i have problem debugger when modules in code call each other. practical example:
a file dog.py contains following code:
import cat print("dog")
the file cat.py following:
import dog print("cat")
when run dog.py (or cat.py) don't have problem , program runs smoothly. however, when try debug it, whole spyder freezes , have kill program.
do know how can fix this? use circular importing, modules use functions in other modules.
thank you!
when run dog.py (or cat.py) don't have problem , program runs smoothly.
afaict that's because script imported under special name ("__main__"
), while module imported under it's own name (here "dog" or "cat"). nb : difference between script , module loaded - passed argument python runtime (python dog.py
) or imported script or module import
statement.
(actually circular imports issues bit more complicated describe above, i'll leave more knowledgeable.)
to make long story short: except particular use case (which more of side effect), python not support circular imports. if have functions (classes, whatever) shared other scripts or modules, put these functions in different module. or if find out 2 modules depends on each other, may want regroup them single module (or regroup parts depend on each other in same module , else in 1 or more other modules).
also: unless it's trivial one-shot util or depends on stdlib, script's content better reduced main
function parsing command-line arguments / reading config files / whatever, importing required modules , starting effective process.
Comments
Post a Comment