Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Issue with debugpy affecting objects refcount

Open
#1,854 7 comments 0 reactions 1 assignee View on GitHub

@rchiodo is already working on this.

Since Mar 4, 2025.

Assessment

This issue has not been assessed yet.

Description

bug needs repro

Environment data

  • debugpy version: 1.8.1
  • OS and version: Windows 11
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.11
  • Using VS Code or Visual Studio: VS Code 1.93.1

Actual behavior

Consider snippet below - when executing with a debugger attached it fails with an error below.

    x.resize(4)
ValueError: cannot resize an array that references or is referenced
by another array in this way.
Use the np.resize function or refcheck=False
import numpy as np
import sys

# import debugpy
# debugpy.listen(5678)
# debugpy.wait_for_client()

x = np.ones(3)
print(sys.getrefcount(x))
# ValueError: cannot resize an array that references or is referenced
# by another array in this way.
# Use the np.resize function or refcheck=False
x.resize(4)
print(x)

Investigating I've noticed 3 different behaviours:

  1. Running it just using python test.py - prints 2 as the refcount and produce no errors.

  2. Running it using VS Code's "Debug Python File"
    Image
    or by uncommenting debugpy part and attaching debugger later - it prints 2 but fails with an error.

  3. Running it with VS Code/debugpy debugger but setting breakpoint at x = np.ones(3) and then stepping through all lines - then it prints 3 and also fails with an error.

Expected behavior

Code execution not to be affected by the debugging process.

Related - https://github.com/IfcOpenShell/IfcOpenShell/issues/6256

Dominant language
Python
Stars
2.5k
Forks
202
Avg merge
5d 1h
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

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.

More from microsoft/debugpy

All issues in microsoft/debugpy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.