A thread import problem
dieter at handshake.de
Sun Jul 22 08:04:37 CEST 2012
Bruce Sherwood <bruce.sherwood at gmail.com> writes:
> Thanks much for this suggestion. I'm not sure I've correctly
> understood the operation "start_new_thread(lambda: __import__(<your
> module>), ())". By "your module" do you mean the user program which
> imported the module that will execute start_new_thread?
By "your_module", I meant what you have called "user.py" elsewhere
in this thread -- the thing that does the animation.
Of course, my suggestion implies that "visual.py" is somewhat changed.
It is supposed to no longer set up the GUI environment automatically
but do so only when its "setup_gui" function is called, and starting
the GUI main loop, too, is no longer automatic but explicite.
> It hadn't
> occurred to me to have A import B and B import A, though now that you
> describe this (if that's indeed what you mean) it makes sense.
I do not propose to do that -- it can lead to problems.
In my proposal, you have two modules: one the "main" module which
sets up the GUI environment, starts the animation in a separate thread
and then activate the GUI main loop. The second module contains
the code you have shown in a previous message.
Of course, the second module can be eliminated by putting its content
into a function and then calling this function in the "start_new_thread"
(instead of "lambda: __import__(...)").
More information about the Python-list