pythondebuggingvisual-studio-codeopenmpptvs

How to debug mpirun Python processes in Visual Studio Code on Ubuntu?


Create /home/bob/foobar.py in Visual Studio Code with the VS Code Docker Extension

import ptvsd
import time
ptvsd.enable_attach(address = ('0.0.0.0', 5678))
ptvsd.wait_for_attach()
time.sleep(2)
print("all righty then")

Set a breakpoint on the last line.

Debug|Add Configuration

In launch.json add to "configurations"

{
   "name": "Python Attach (Remote Debug ptsvd default)",
   "type": "python",
   "request": "attach",
   "pathMappings": [
       {
          "localRoot": "/home/bob", // You may also manually specify the directory containing your source code.
          "remoteRoot": "/home/bob" // Linux example; adjust as necessary for your OS and situation.
       }
    ],
            "port": 5678, // Set to the remote port.
            "host": "0.0.0.0" // Set to your remote host's public IP address.
        },
$ python -m pip install --user --upgrade ptvsd
$ python foobar.py 

Start the debugger with configuration "Python Attach (Remote Debug ptsvd default)". It stops at the breakpoint.

But if I run mpirun

$ mpirun --allow-run-as-root -np 2 -H localhost:2 -bind-to none -map-by slot -x PATH -mca pml ob1 -mca btl ^openib python ./foobar.py

I get the error socket.error: [Errno 98] Address already in use

Is there a way to assign multiple ports for an arbitrary number of processes in launch.json and in foobar.py?


Solution

  • This is not currently possible but has been added by the ptvsd team as a possible enhancement. Vote it up if this is important to you. Upvotes for this team seem to move features up the to-do list.