Where to place imports

Jean-Paul Calderone exarkun at divmod.com
Fri Jan 23 20:03:41 CET 2009


On 23 Jan 2009 18:50:00 GMT, Duncan Booth <duncan.booth at invalid.invalid> wrote:
> [snip]
>
>BTW, if you ever find you are starting to write multi-threaded applications
>then you'll really regret it if you reuse code which does imports from
>inside functions. If two or more threads try to import a module
>simultaneously then one of them might find it that not everything is
>defined in the module exists when it tries to use it.

What makes you say this?  There is an import lock (beyond the GIL) which
should prevent a thread from ever seeing a partially initialized module.

Jean-Paul



More information about the Python-list mailing list