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.

RuntimeError('context has already been set')

See original GitHub issue

after installing 0.5.1 on Ubuntu I got following error:

Traceback (most recent call last):
  File "/home/daniel/.local/bin/mnelab", line 8, in <module>
    sys.exit(main())
  File "/home/daniel/.local/lib/python3.6/site-packages/mnelab/__main__.py", line 27, in main
    mp.set_start_method("spawn")  # required for Linux/macOS
  File "/usr/lib/python3.6/multiprocessing/context.py", line 242, in set_start_method
    raise RuntimeError('context has already been set')
RuntimeError: context has already been set

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

6reactions
danieltomaszcommented, Oct 24, 2019

Running this twice on my computer (Python 3.6.8, Ipython 7.8.0)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import multiprocessing as mp
mp.set_start_method('spawn')

throw the same error, so it seems that at least on my computer when the Mnelab is starting the spawn is invoked more than once (but I don’t know how)

runfile('/home/daniel/PhD/notebooks/untitled1.py', wdir='/home/daniel/PhD/notebooks')
Traceback (most recent call last):

  File "/home/daniel/PhD/notebooks/untitled1.py", line 5, in <module>
    mp.set_start_method('spawn')

  File "/usr/lib/python3.6/multiprocessing/context.py", line 242, in set_start_method
    raise RuntimeError('context has already been set')

RuntimeError: context has already been set

Using force=TRUE solve the problem (see the issue I linked before)

mp.set_start_method('spawn', force=True)
0reactions
cbrnrcommented, Oct 29, 2019

@danieltomasz could you please try the following:

  • Comment out the line mp.set_start_method("spawn") in __main__.py
  • Insert the line mp.set_start_method("spawn") in mainwindow.py as the first line of the __init__ function of the MainWindow class (should be line 90).

Please let me know if that works for you. Make sure to test if multiprocessing works by loading a file and computing ICA (this is currently the only thing which requires multiprocessing).

Read more comments on GitHub >

github_iconTop Results From Across the Web

RuntimeError: context has already been set(multiprocessing)
I use a spawn start methods to share CUDA tensors between processes import torch torch.multiprocessing.set_start_method("spawn") import ...
Read more >
mp.set_start_method('spawn') triggered an error saying the ...
With mp.set_start_method('spawn') , I got the error RuntimeError: context has already been set and if I use mp.set_start_method('spawn', ...
Read more >
Multiprocessing for cuda error - PyTorch Forums
I want to use torch.multiprocessing to accelerate my loop, however there are some errors . I can't absolutely understand the shared cuda ...
Read more >
OS 3.3.12 crashes when spawning experiment process ...
OS 3.3. 12 crashes when spawning experiment process, "context has already been set" — Forum.
Read more >
Multiprocessing Start Methods - Super Fast Python
Running the example results in a RuntimeError indicating that the start method has already been set. 1. 2. 3. 4. Start Method: spawn....
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