question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parallel crashed on python 3.6 when running in vscode debugger

See original GitHub issue

My environment is python 3.6 and I ran a simple script file like below:

from math import sqrt
from joblib import Parallel, delayed


def main():
    print('simulate workers, testing parallel')
    Parallel(n_jobs=2)(delayed(sqrt)(i ** 2) for i in range(10))


if __name__ == '__main__':
    print('simulate workers, testing parallel')
    Parallel(n_jobs=2)(delayed(sqrt)(i ** 2) for i in range(10))

And facing a crash:

Screenshot 2019-04-05 10 15 19

Below is the log details: E00001.438: Exception escaped from start_client

        Traceback (most recent call last):
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/log.py", line 110, in g
            return f(*args, **kwargs)
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/pydevd_hooks.py", line 74, in start_client
            sock, start_session = daemon.start_client((host, port))
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/daemon.py", line 214, in start_client
            with self.started():
          File "/Users/fans3210/anaconda3/envs/assignQuestion-py36/lib/python3.6/contextlib.py", line 81, in __enter__
            return next(self.gen)
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/daemon.py", line 110, in started
            self.start()
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/daemon.py", line 145, in start
            raise RuntimeError('already started')
        RuntimeError: already started

/Users/fans3210/anaconda3/envs/assignQuestion-py36/lib/python3.6/site-packages/joblib/externals/loky/backend/semaphore_tracker.py:74: UserWarning: semaphore_tracker: process died unexpectedly, relaunching. Some semaphores might leak. warnings.warn('semaphore_tracker: process died unexpectedly, ’ E00001.467: Exception escaped from start_client

        Traceback (most recent call last):
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/log.py", line 110, in g
            return f(*args, **kwargs)
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/pydevd_hooks.py", line 74, in start_client
            sock, start_session = daemon.start_client((host, port))
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/daemon.py", line 214, in start_client
            with self.started():
          File "/Users/fans3210/anaconda3/envs/assignQuestion-py36/lib/python3.6/contextlib.py", line 81, in __enter__
            return next(self.gen)
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/daemon.py", line 110, in started
            self.start()
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/daemon.py", line 145, in start
            raise RuntimeError('already started')
        RuntimeError: already started

E00001.481: Exception escaped from start_client

        Traceback (most recent call last):
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/log.py", line 110, in g
            return f(*args, **kwargs)
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/pydevd_hooks.py", line 74, in start_client
            sock, start_session = daemon.start_client((host, port))
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/daemon.py", line 214, in start_client
            with self.started():
          File "/Users/fans3210/anaconda3/envs/assignQuestion-py36/lib/python3.6/contextlib.py", line 81, in __enter__
            return next(self.gen)
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/daemon.py", line 110, in started
            self.start()
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/daemon.py", line 145, in start
            raise RuntimeError('already started')
        RuntimeError: already started

E00001.515: Exception escaped from start_client

        Traceback (most recent call last):
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/log.py", line 110, in g
            return f(*args, **kwargs)
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/pydevd_hooks.py", line 74, in start_client
            sock, start_session = daemon.start_client((host, port))
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/daemon.py", line 214, in start_client
            with self.started():
          File "/Users/fans3210/anaconda3/envs/assignQuestion-py36/lib/python3.6/contextlib.py", line 81, in __enter__
            return next(self.gen)
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/daemon.py", line 110, in started
            self.start()
          File "/Users/fans3210/.vscode/extensions/ms-python.python-2019.3.6215/pythonFiles/lib/python/ptvsd/daemon.py", line 145, in start
            raise RuntimeError('already started')
        RuntimeError: already started

The only solution I can use is to set" “prefer = ‘threads’” in the function call. Appreciated if someone could help!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:13
  • Comments:18

github_iconTop GitHub Comments

26reactions
Eraliencommented, Jun 12, 2019

Hey, I saw a solution by amittleider and it worked for me. Paste it here:

On Ubuntu, putting this at the top of the main entrypoint file worked for me:

import multiprocessing
multiprocessing.set_start_method('spawn', True)
7reactions
anerisheth19commented, Dec 9, 2019

Do the following to avoid the semaphore error:

  1. Write the following piece of code in the beginning of the .py file you are debugging. import multiprocessing multiprocessing.set_start_method('spawn', True)
  2. In the debug configurations file - launch.json, add the following: "subProcess": true, and for Pytorch DataLoader function, set num_worker threads as ‘0’.

Hope this helps you! It worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging configurations for Python apps in Visual Studio Code
The Python extension supports debugging of several types of Python ... To initialize debug configurations, first select the Run view in the sidebar:....
Read more >
VS Code Debugger not working for python - Microsoft Q&A
When VS Code was updated to 1.64.0 it seems to have broken Python debugging. Clicking on "Run Python File" works fine. Clicking on...
Read more >
Debug a Parallel MPI program in Visual Studio Code - YouTube
I explain how you can debug a parallel MPI program with visual studio ( vs) code. I run it on Linux Ubuntu. For...
Read more >
Debugger crashes on Python 3.6.0 : PY-48069 - YouTrack
and set breakpoint on this line, but the debug run crash with output below: /Users/xxx/.pyenv/versions/XXX-3.6/bin/python "/Users/xxx/Library/Application ...
Read more >
Developing with asyncio — Python 3.11.1 documentation
By default asyncio runs in production mode. In order to ease the development asyncio has a debug mode. There are several ways to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found