[Python-Dev] Deadlock by a second import in a thread

Facundo Batista facundobatista at gmail.com
Fri Oct 26 04:34:56 CEST 2007


2007/10/20, Nick Coghlan <ncoghlan at gmail.com>:

> bb.py is broken - importing a module should never spawn a new thread as
> a side effect (precisely because it will deadlock if the spawned thread
> tries to do an import, which can happen in a myriad of ways).

Exactly, :(.

I changed timeobject.c to import _strptime once at init time. But the
problem still happened, because the function strptime needs to parse
the format, and this involves a regex sub() call, which finish in a
pattern_subx() call in _srec.c, which needs to call to _subx() in the
re module through the call() function, which finally issues another
import, creating the deadlock again.

In short: you can not avoid a second import unless you rewrite *a lot*
of internal code.

BTW, I'll leave the optimization of importing strptime one time,
there's no reason to try to import it everytime strptime() is called.

Regards,

-- 
.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


More information about the Python-Dev mailing list