microsoft / debugpy

An implementation of the Debug Adapter Protocol for Python

Home Page:https://pypi.org/project/debugpy/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I use debugpy in multiprocessing program?

ggggfff1 opened this issue · comments

I have a multiprocessing program, when I use debugpy to run this code. It appear:

RuntimeError: Can't listen for client connections: [Errno 98] Address already in use

the code simpilfy as:

import multiprocessing
multiprocessing.set_start_method('spawn', True)
import debugpy
debugpy.listen(12361)
print('wait debugger')
debugpy.wait_for_client()
print("Debugger Attached")
manager = Manager()

when the code run into manager = Manager() , error occur.

How can I use debugpy in multiprocessing program?

I have found an alternative way to solve this problem, which is to use debugpy in the subprocess.
Specifically, we don't initialize debugpy at the beginning of our code. Instead, we can initialize it within the subprocess function.

like this:

def run():
import debugpy
debugpy.listen(12361)
print('wait debugger')
debugpy.wait_for_client()
print("Debugger Attached")
'''Start you subprocess code'''

manager = Manager()
result_dict = manager.dict()
file_lock = manager.Lock()
processes = [ Process(target=run, args=())]