pypa / pypa/setuptools

Can't pdb a setup() call in Windows cmd.exe

Open
#433 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug minor
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

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.


Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing python3.4 -m pdb setup.py build_ext in Windows cmd.exe and trace the ValueError: underlying buffer has been detached failure. Inspect the distutils.dist code that switches sys.stdout and the related pdb behavior, then compare the existing workaround from distribute issue 334. Done means the command no longer fails in this corner case and the behavior is covered by an appropriate test, if the project has one.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.