Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to launch debug with multiprocessing #9607

Closed
emailweixu opened this issue Jan 15, 2020 · 3 comments
Closed

Fail to launch debug with multiprocessing #9607

emailweixu opened this issue Jan 15, 2020 · 3 comments
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@emailweixu
Copy link

emailweixu commented Jan 15, 2020

Environment data

  • VS Code version: 1.41.1
  • Extension version (available under the Extensions sidebar): 2020.1.58038
  • OS and version: Ubuntu 18.04
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv
  • Relevant/affected Python packages and their versions:
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977):

Expected behaviour

Able to launch debug. I suspect it might be caused by the use of ptvsd_laucher.py, which is supposed to be outdated. But I have no idea why ptvsd_launcher.py is selected instead of new_ptvsd. I even tried changing the experiment groups for DebugAdapterFactory and PtvsdWheels37 in ~/.vscode-server/extensions/ms-python.python-2020.1.58038/experiments.json. But still not able to debug.

Actual behaviour

Get error:

RuntimeError: already started

Steps to reproduce:

import multiprocessing
import time

def func():
    while True:
        print(1)
        time.sleep(1)


proc = multiprocessing.Process(target=func)
proc.start()
while True:
    print(2)
    time.sleep(1)

Logs

Output from Terminal

$ cd /home/weixu/code/test ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /home/weixu/venvs/tf2/bin/python /home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 36819 /home/weixu/code/test/process.py 
2
E00000.258: Exception escaped from start_client
            
            Traceback (most recent call last):
              File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/log.py", line 110, in g
                return f(*args, **kwargs)
              File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/pydevd_hooks.py", line 74, in start_client
                sock, start_session = daemon.start_client((host, port))
              File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/daemon.py", line 214, in start_client
                with self.started():
              File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
                return next(self.gen)
              File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/daemon.py", line 110, in started
                self.start()
              File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/daemon.py", line 145, in start
                raise RuntimeError('already started')
            RuntimeError: already started
            

Traceback (most recent call last):
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 432, in main
    run()
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/usr/lib/python3.6/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/weixu/code/test/process.py", line 11, in <module>
    proc.start()
  File "/usr/lib/python3.6/multiprocessing/process.py", line 105, in start
    self._popen = self._Popen(self)
  File "/usr/lib/python3.6/multiprocessing/context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/usr/lib/python3.6/multiprocessing/context.py", line 277, in _Popen
    return Popen(process_obj)
  File "/usr/lib/python3.6/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/usr/lib/python3.6/multiprocessing/popen_fork.py", line 66, in _launch
    self.pid = os.fork()
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_monkey.py", line 528, in new_fork
    _on_forked_process()
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/_vendored/pydevd/_pydev_bundle/pydev_monkey.py", line 50, in _on_forked_process
    pydevd.settrace_forked()
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/_vendored/pydevd/pydevd.py", line 2427, in settrace_forked
    patch_multiprocessing=True,
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/_vendored/pydevd/pydevd.py", line 2179, in settrace
    wait_for_ready_to_run,
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/_vendored/pydevd/pydevd.py", line 2230, in _locked_settrace
    debugger.connect(host, port)  # Note: connect can raise error.
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/_vendored/pydevd/pydevd.py", line 1060, in connect
    s = start_client(host, port)
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/pydevd_hooks.py", line 136, in _start_client
    return start_client(daemon, h, p)
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/log.py", line 110, in g
    return f(*args, **kwargs)
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/pydevd_hooks.py", line 74, in start_client
    sock, start_session = daemon.start_client((host, port))
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/daemon.py", line 214, in start_client
    with self.started():
  File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/daemon.py", line 110, in started
    self.start()
  File "/home/weixu/.vscode-server/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/old_ptvsd/ptvsd/daemon.py", line 145, in start
    raise RuntimeError('already started')
RuntimeError: already started
Terminated
@emailweixu emailweixu added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Jan 15, 2020
@karthiknadig
Copy link
Member

karthiknadig commented Jan 15, 2020

@emailweixu multiprocessing is supported in the newer version of the debugger. We have enabled it for about 20% of the users. Looks like you are not in the group where it is enabled. If you want to try it out please, install the insiders version of the extension (here https://pvsc.blob.core.windows.net/extension-builds/ms-python-insiders.vsix)
Add this to your settings:

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

You have to reload after adding the settings. Check the Python logs to make sure you are added to the experiments:

User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'

If you want to make it work using the old debugger, you can do it using this work around:
microsoft/ptvsd#943

@emailweixu
Copy link
Author

@karthiknadig Thanks. Your suggestion works. But I wonder why changing ~/.vscode-server/extensions/ms-python.python-2020.1.58038/experiments.json into the following does not work:

{
        "name": "DebugAdapterFactory - control",
        "salt": "DebugAdapterFactory",
        "min": 0,
        "max": 0
    },
    {
        "name": "DebugAdapterFactory - experiment",
        "salt": "DebugAdapterFactory",
        "min": 0,
        "max": 100
    },
    {
        "name": "PtvsdWheels37 - control",
        "salt": "DebugAdapterFactory",
        "min": 0,
        "max": 0
    },
    {
        "name": "PtvsdWheels37 - experiment",
        "salt": "DebugAdapterFactory",
        "min": 0,
        "max": 100
    },

@karthiknadig
Copy link
Member

@emailweixu that is a back up file in-case extension cannot access the file here in the repo. This is so that if we want to turn off an experiment we can do it globally.

The Opt-in / Opt-out settings take precedence over the experiments.json in the repo, which takes precedence over the local experiments.ts.

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jan 16, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

2 participants