[Python-Dev] Fwd: Deadlock by a second import in a thread
Facundo Batista
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
> scope.)
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,
you'll never
be sure.
What do you think?
Thank you!
--
. Facundo
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/
More information about the Python-Dev
mailing list