[issue34609] Importing certain modules while debugging raises an exception

Antoine Pitrou report at bugs.python.org
Sat Sep 29 06:24:57 EDT 2018


Antoine Pitrou <pitrou at free.fr> added the comment:

I think pperry nailed it above:

> Pdb fails because it is attempting to import the readline module every time its `trace_dispatch` is called, and the import implementation is not reentrant in that way.

More precisely, _ModuleLock.acquire() in https://github.com/python/cpython/blob/master/Lib/importlib/_bootstrap.py#L101 is not reentrant.  If pdb steps into that function and tries to call it again by making an "import" call, `_blocking_on[tid]` will be overwritten and then deleted inside the nested call, so `del _blocking_on` in the enclosing call will raise a KeyError.

I think the solution would be either one of:
1) pdb avoids doing anything import-related as part of its step function
2) pdb avoids stepping inside importlib internals (e.g. by blacklisting importlib modules)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34609>
_______________________________________


More information about the Python-bugs-list mailing list