Skip to content

Commit 133781d

Browse files
committed
Allow only one instance of debugpy to be started across the process
1 parent 48fd27c commit 133781d

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

ida/idacode_utils/socket_handler.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,28 @@ def create_env():
1212
"__name__": "__main__"
1313
}
1414

15+
debugpy_host = ""
16+
debugpy_port = 0
17+
1518
def start_debug_server():
19+
# At most one instance of debugpy can ever be created per process.
20+
# Reference: https://github.com/microsoft/debugpy/issues/297
21+
global debugpy_host, debugpy_port
22+
if debugpy_port and debugpy_port:
23+
print("[IDACode] debugpy server is already listening on {}:{}".format(debugpy_host, debugpy_port))
24+
return
25+
26+
# Install hook for os.getcwd
27+
hooks.install()
28+
29+
# Start debugpy server
1630
if settings.LOGGING:
1731
tmp_path = tempfile.gettempdir()
1832
debugpy.log_to(tmp_path)
1933
print("[IDACode] Logging to {} with pattern debugpy.*.log".format(tmp_path))
20-
debugpy.configure({ "python": settings.PYTHON })
21-
debugpy.listen((settings.HOST, settings.DEBUG_PORT))
22-
print("[IDACode] IDACode debug server listening on {address}:{port}".format(address=settings.HOST, port=settings.DEBUG_PORT))
34+
debugpy.configure(python=settings.PYTHON)
35+
debugpy_host, debugpy_port = debugpy.listen((settings.HOST, settings.DEBUG_PORT))
36+
print("[IDACode] Started debugpy server on {}:{}".format(debugpy_host, debugpy_port))
2337

2438
class SocketHandler(tornado.websocket.WebSocketHandler):
2539
def open(self):

0 commit comments

Comments
 (0)