microsoft/ptvsd

Multi-processing issue in VS code debugger

gauravmunjal13 opened this issue · 5 comments

Environment data

  • PTVSD version: 1.46.1
  • OS and version: Darwin x64 19.4.0
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.5.3 64-bit
  • Using VS Code or Visual Studio: VS code

Actual behavior

On using VS code for debugging PyTorch code on enumerator(data_loader) line, there is the following error:

RuntimeError: already started
E00019.065: Exception escaped from start_client
...
AssertionError: can only join a child process

Expected behavior

The error happening because of doing multi-processing in data-loader. This has happened specifically when I updated the VS code to 1.46.1 yesterday.

The expected behavior is not to give any error on enumerating the data loader in PyTorch, which was the case before updating VS code.

Steps to reproduce:

  1. Update the VS code to 1.46.1
  2. Run the VS code debugger for enumerating the data loader in PyTorch

However, if I set num_workers=0 or use the following code before enumerating data loader resolves the issue:

import multiprocessing
multiprocessing.set_start_method('spawn', True)

Is there another way to resolve this? Or I am missing any configuration settings?

Thank you!

Kind regards,
Gaurav Kumar

I would like to add another strange behaviour with the debugger on using the following code before iterating over the data loader in PyTorch:

import multiprocessing
multiprocessing.set_start_method('spawn', True)

When the execution comes across enumerate(data_loader), it doesn't step into the get_item() method of the data loader even if I have set-up the breakpoints.

However, this wasn't observed on rather using num workers = 0.

PTVSD version: 1.46.1

Isn't it PTVSD version: 4.3.2?
I updated vscode to 1.46.1, then had the same error.
I used DataLoader in pytorch, and multiprocessing was used in DataLoader.
So, multiprocessing is related to the bug, I guess.

E00013.182: Exception escaped from start_client
            
            Traceback (most recent call last):
              File "/home/hoge/.vscode-server/extensions/ms-python.python-2020.6.89148/pythonFiles/lib/python/old_ptvsd/ptvsd/log.py", line 110, in g
                return f(*args, **kwargs)
              File "/home/hoge/.vscode-server/extensions/ms-python.python-2020.6.89148/pythonFiles/lib/python/old_ptvsd/ptvsd/pydevd_hooks.py", line 74, in start_client
                sock, start_session = daemon.start_client((host, port))
              File "/home/hoge/.vscode-server/extensions/ms-python.python-2020.6.89148/pythonFiles/lib/python/old_ptvsd/ptvsd/daemon.py", line 214, in start_client
                with self.started():
              File "/usr/lib/python3.5/contextlib.py", line 59, in __enter__
                return next(self.gen)
              File "/home/hoge/.vscode-server/extensions/ms-python.python-2020.6.89148/pythonFiles/lib/python/old_ptvsd/ptvsd/daemon.py", line 110, in started
                self.start()
              File "/home/hoge/.vscode-server/extensions/ms-python.python-2020.6.89148/pythonFiles/lib/python/old_ptvsd/ptvsd/daemon.py", line 145, in start
                raise RuntimeError('already started')
            RuntimeError: already started

There seems to be the same error in vscode-python repo.
microsoft/vscode-python#12481
microsoft/vscode-python#12476

You're still running ptvsd 4. This is possible even with the most recent vscode-python version, if you have explicitly opted out from the new debugger experiment. Can you please check your settings, and make sure that you DON'T have any of this:

    "python.experiments.optOutFrom": [
        "DebugAdapterFactory - experiment",
        "PtvsdWheels37 - experiment"
    ],

(conversely, you can use "python.experiments.optIn" to force it - but you shouldn't need to, if you haven't opted out)

Duplicate of microsoft/vscode-python#12481 - please see the comments there for a workaround.