Skip to content

ResourceWarning: unclosed socket #1812

Closed
@YoniChechik

Description

@YoniChechik

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions