
Description
Originally reported by: embray (Bitbucket: embray, GitHub: embray)
I ran across this while trying to run
$ python3.4 -m pdb setup.py build_ext
on Windows, in a standard cmd.exe prompt, while trying to debug an unrelated issue.
This results in a traceback stemming from Pdb ending with:
ValueError: underlying buffer has been detached
the full traceback isn't really important. This traces back to https://bitbucket.org/tarek/distribute/issues/311 -- because the original sys.stdout
's raw buffer is detached, Pdb breaks. https://bitbucket.org/tarek/distribute/issues/334 added a partial workaround, but it's acknowledge there that there may be corner cases not covered. This is one such corner case.
One workaround is to manually edit the distutils/setuptools/etc. source code and add a pdb.set_trace()
closer to the code you wish to debug (so that PDB is not invoked until after this sys.stdout
switcheroo).
Some other possibilities might be to monkeypatch distutils.dist
to replace the print()
function (this all only applies to Python 3 anyways IIUC) or alternatively pdb can be monkeypatched. The code the messes with sys.stdout
could be rewritten as a context manager that handles this.
It's probably not worth it though since this is indeed a narrow corner case. But if you would accept such a patch I'll think about writing it. In the meantime just thought I'd document the issue.