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) |