Skip to content

Try soft-kill before hard-kill when terminating debugger #1022

@tjnd89

Description

@tjnd89

Type: Bug

I've observed a strange behavior where VSCode does not release COM object references while debugging. PyCharm works fine. To see this in action do the following:

Start Excel (the problem occurs with other apps too, I'm using Excel for this example only because most people have it).

From the command line, run the script "excel_test.py" below. It attaches to the running Excel application and tries to call a non-existent method hi(). An exception is thrown and the script will exit, as expected.

import win32com.client as w32c

# Attach to a running Excel
app = w32c.GetActiveObject("Excel.Application")

# This will throw an exception
app.hi()

print("done")

Quit Excel manually by closing it via the UI. Note in the task manager that the Excel.exe process has shut down. This is all as expected.

Repeat the same steps but run the script using VSCode debug mode. When the exception is thrown the debugger halts execution. Press the Stop button on the debugger tool bar to terminate the script. After quitting Excel, notice that the UI has shutdown, but the Excel.exe process is still running. You now have a zombie process.

Following this same pattern in PyCharm debug mode works fine, the process goes away as expected.

Somehow it appears that VSCode is not properly releasing the COM object reference when exiting debug mode. Am I missing some weird setting or something, or is it just broken?

I'm running Python 3.9.12, pywin32 302, VSCode 1.70.2.

I've also opened up a StackOverflow question on this at https://stackoverflow.com/questions/73401543/vscode-debugger-not-releasing-com-object-reference-when-a-python-script-throws-a.

Extension version: 2022.12.1
VS Code version: Code 1.70.2 (e4503b30fc78200f846c62cf8091b76ff5547662, 2022-08-16T05:35:13.448Z)
OS version: Windows_NT x64 10.0.22000
Modes:

System Info
Item Value
CPUs Intel(R) Core(TM) i9-10900K CPU @ 3.70GHz (20 x 3696)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 31.90GB (17.48GB free)
Process Argv C:\Users\tj\OneDrive - Exa Research\Training\ODTK\Integrating\Exercises --crash-reporter-id 07d7cc17-f9d3-4972-9a41-087017e04f32
Screen Reader no
VM 0%

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions