[Python-Dev] Fwd: Deadlock by a second import in a thread
facundobatista at gmail.com
Sat Oct 20 01:12:23 CEST 2007
2007/10/19, Adam Olsen <rhamph at gmail.com>:
> The solution then is, if your python file will ever be imported, you
> must write a main function and do all the work there instead. Do not
> write it in the style of a script (with significant work in the global
I had this a as a good coding style, not so mandatory.
I agree with you that the OP shouldn't be doing that, but note that
the main problem arises here because it's completely unpredictable the
import in strptime for an external user.
Do you recommend to close the bug as "won't fix" saying something like...
The deadlock happens because strptime has an import inside it, and
recursive imports are not allowed in different threads.
As a general rule and good coding style, don't run your code when the
module is imported, but put it in a function like "main" in the second file,
import it and call it from the first one. This will solve your problem.
Note that this happens to you with strptime, but could happen with a lot
of functions that do this internal import of something else. So,
What do you think?
More information about the Python-Dev