On Oct 14, 2012 11:27 AM, "Devin Jeanpierre" <jeanpierreda@gmail.com> wrote:
> I did this once, because I needed to rewrite a blocking API and wanted
> to use Twisted, except that I made the mistake of starting the thread
> when the module was created instead of on first call. This lead to a
> deadlock because of the global import lock... :(  In principle I don't
> know why this would be a terrible awful idea, if it was done right,
> but maybe people with more experiences with threaded code can correct
> me.
>
> (The whole thread daemon thing necessary to make it act like a
> synchronous program, might be terribly insane and therefore an idea
> killer. I'm not sure.)
>
> I'm under the understanding that the global import lock won't cause
> this particular issue anymore as of Python 3.3, so perhaps starting a
> reactor on import is reasonable.

Yeah, while a global import lock still exists, it's used just long enough to get a per-module lock.  On top of that, the import system now uses importlib (read: pure Python) for most functionality, which has bearing on threading and ease of better accommodating async if needed.

-import