Welcome to Circular Import Hell
I'd seen rumors of it.
Didn't think it could happen to me.
Hey, I'm just a beginner/noob Python coder; still not grokking much of it in my nascent and evolving cusp state,
Those alleged "circular import" lock ups should happen only to them guru coding experts who are trying to be too clever by a half! Not me. Not yet. (Right?)
At first my computer would just freeze up. The cursor stopped moving. I couldn't do anything but shut off the power and boot up again. I worried that PyCharm or Python 3.13.5 had permanently damaged my computer!
After many a failed runs and reboots, I managed to move some of the modular code around such that I got a bunch of error messages in the PyCharm console area. It said something about a particular variable not being defined. I looked in my code. Damn it. It is defined. Right there. Very infuriating.
Some deep breathes and I re-read the error traceback messages more carefully. Somethingabout this probably being a "circular import" problem. What the hell is that?
Watched some tutorial videos. Here, here and here. Still confused. Stepped back and thought about it. I think I now understand the problem. Still don't have an obvious solution except to stop being extra clever by a half.
To the left is my visual-based understanding of the circular import, lock-up problem.Suppose that midway down "B" we hit a call for a Var_A in Module "A" or for a Function_AA in "A". However that part of Module "A" that defines the called-for objects has not yet been interpreted. So the called-for objects are "undefined" and our interpreter locks up.
MORE TO EXPLORE
What is the import loop problem in Python? (Google results)
What is the Python NameSpace and How affected by Import
... to be continued ???
Comments
Post a Comment