Repository navigation
Closed
Labels
Fixed in next releaseThis issue has been fixed, but won't be available to customers until the next release.needs reproIssue has not been reproduced yet
Description
Environment data
- debugpy version: 1.8.9
- OS and version: linux ubuntu 22.04 host via ssh via docker devcontainer (nvidia/cuda:12.1.1-runtime-ubuntu22.04)
- Python version: uv, python 3.12.8
- Using VS Code or Visual Studio: vscode 1.96.3
Actual behavior
getting unclosed socket warning only when running via debbuger (only extension installed is python + pylance + debugpy):
Exception ignored in: <socket.socket fd=5, family=2, type=1, proto=0, laddr=('127.0.0.1', 57946), raddr=('127.0.0.1', 33845)>
ResourceWarning: unclosed <socket.socket fd=5, family=2, type=1, proto=0, laddr=('127.0.0.1', 57946), raddr=('127.0.0.1', 33845)>
Expected behavior
should not pop
Steps to reproduce:
here is a full code repro:
import time
import warnings
from multiprocessing import Process, set_start_method
warnings.filterwarnings("error")
def script_runner():
def decorate(func):
def wrapper(*args, **kwargs):
set_start_method("spawn")
func(*args, **kwargs)
return wrapper
return decorate
@script_runner()
def main():
processes = [Process(target=worker_function, args=(f"Worker-{i}",)) for i in range(5)]
# Start all processes
for process in processes:
process.start()
# Wait for all processes to complete
for process in processes:
process.join()
print("All processes have completed.")
def worker_function(name: str) -> None:
print(f"Process {name} is starting")
time.sleep(2) # Simulate work
print(f"Process {name} has finished")
if __name__ == "__main__":
# Create multiple processes
main()output:
Process Worker-2 is starting
Process Worker-0 is starting
Process Worker-3 is starting
Process Worker-1 is starting
Process Worker-2 has finished
Process Worker-4 is starting
Process Worker-0 has finished
Exception ignored in: <socket.socket fd=5, family=2, type=1, proto=0, laddr=('127.0.0.1', 57916), raddr=('127.0.0.1', 33845)>
ResourceWarning: unclosed <socket.socket fd=5, family=2, type=1, proto=0, laddr=('127.0.0.1', 57916), raddr=('127.0.0.1', 33845)>
Process Worker-3 has finished
Exception ignored in: <socket.socket fd=5, family=2, type=1, proto=0, laddr=('127.0.0.1', 57946), raddr=('127.0.0.1', 33845)>
ResourceWarning: unclosed <socket.socket fd=5, family=2, type=1, proto=0, laddr=('127.0.0.1', 57946), raddr=('127.0.0.1', 33845)>
Process Worker-1 has finished
Process Worker-4 has finished
All processes have completed.
Metadata
Metadata
Assignees
Labels
Fixed in next releaseThis issue has been fixed, but won't be available to customers until the next release.needs reproIssue has not been reproduced yet
Activity
rchiodo commentedon Jan 15, 2025
Thanks for the issue, but I don't think this is something we'd bother fixing.
bersbersbers commentedon Feb 3, 2025
I have come across essentially the same issue. In my eyes, despite the length of the example code above, the problem lies more or less in
warnings.filterwarnings("error")- this code already reproduces the issue:That it's a very old issue rooted deep in the Python code. However, if the very useful discussion in https://emptysqua.re/blog/against-resourcewarnings-in-python-3/#comment-514722438 is still current, that warning is off by default, and
So modifying that warnings filter more carefully might fix the warnings output.
Still, since this warning
... I wonder if debugpy could go ahead and just explicitly close their socket(s) instead of relying on the Python garbage collector to do so. Happy to help with a PR if someone can point me into the right direction (any maybe hint at why this is not an obvious one-liner, if it isn't).
rchiodo commentedon Feb 3, 2025
This might be where you'd start. It's the handling of shutting down when the debugger is exiting:
https://vscode.dev/github/microsoft/debugpy/blob/main/src/debugpy/adapter/sessions.py#L135
bersbersbers commentedon Feb 4, 2025
Thanks, I think I got somewhere!
Instructions:
See
Then replace
debugpy\_vendored\pydevd\pydevd.pywith the version from https://github.com/bersbersbers/debugpy/commit/47f1f4e93d7ac6d4496cc2b736967777e52cb7ea.Re-run
See
(nothing)
Voila! I am 99% sure there is better location for the closing of the socket, but I am happy I got this prototype to begin with.
bersbersbers commentedon Feb 5, 2025
For the record, simpler reproduction checks not requiring VS Code at all: checkout
debugpyand runSuppress warning on exit by properly closing `pydevd` socket (#1826)
rchiodo commentedon Mar 5, 2025
This issue should be fixed in the latest build of debugpy. It should ship with VS code in a future version of the Python Debugger Extension or you can install your own debugpy from pypi
fix(deps): update backend dependencies (patch) (patch)
Merge branch 'renovate/patch-backend-dependencies' into 'main'