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

Error running in Visual Studio Code: AttributeError: Can't get attribute 'process_background_job' on <module '__main__' (built-in)> #5

Open
miohtama opened this issue Nov 25, 2023 · 2 comments

Comments

@miohtama
Copy link

miohtama commented Nov 25, 2023

I have the simple notebook with a single cell:

import parallelbar

def process_background_job(a, b):
    return a + b

combinations = [
    (1, 1),
    (2, 3),
    (3, 4),
]

results = parallelbar.progress_starmap(
    process_background_job,
    combinations,
    n_cpu=4,
)

print(results)

Running with Visual Studio Code gives

Process SpawnPoolWorker-18:
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/pool.py", line 114, in worker
    task = get()
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/queues.py", line 367, in get
    return _ForkingPickler.loads(res)
AttributeError: Can't get attribute 'process_background_job' on <module '__main__' (built-in)>
Process SpawnPoolWorker-19:
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/pool.py", line 114, in worker
    task = get()
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/queues.py", line 367, in get
    return _ForkingPickler.loads(res)
AttributeError: Can't get attribute 'process_background_job' on <module '__main__' (built-in)>
Process SpawnPoolWorker-20:
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/pool.py", line 114, in worker
    task = get()
  File "/opt/homebrew/Cellar/[email protected]/3.10.13/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/queues.py", line 367, in get
    return _ForkingPickler.loads(res)
AttributeError: Can't get attribute 'process_background_job' on <module '__main__' (built-in)>

Apparently parallerbar does not work with Jupyter notebooks?

  • macOS
  • Python 3.10
  • Visual Studio Code 1.84.2

Jupyter packages:

comm                            0.2.0        Jupyter Python Comm implementa...
ipykernel                       6.27.0       IPython Kernel for Jupyter
ipywidgets                      8.1.1        Jupyter interactive widgets
jupyter                         1.0.0        Jupyter metapackage. Install a...
jupyter-client                  8.6.0        Jupyter protocol implementatio...
jupyter-console                 6.6.3        Jupyter terminal console
jupyter-core                    5.5.0        Jupyter core package. A base p...
jupyter-events                  0.6.3        Jupyter Event System library
jupyter-lsp                     2.2.0        Multi-Language Server WebSocke...
jupyter-server                  2.10.0       The backend—i.e. core services...
jupyter-server-terminals        0.4.4        A Jupyter Server Extension Pro...
jupyterlab                      4.0.9        JupyterLab computational envir...
jupyterlab-pygments             0.3.0        Pygments theme using JupyterLa...
jupyterlab-server               2.24.0       A set of server components for...
jupyterlab-widgets              3.0.9        Jupyter interactive widgets fo...
nbconvert                       7.11.0       Converting Jupyter Notebooks
nbformat                        5.9.2        The Jupyter Notebook format
notebook                        7.0.6        Jupyter Notebook - A web-based...
qtconsole                       5.5.1        Jupyter Qt console
widgetsnbextension              4.0.9        Jupyter interactive widgets fo...
@miohtama
Copy link
Author

Command line ipython gives the same error.

@dubovikmaster
Copy link
Owner

Hi.
You should run your code after if __name__==‘__main__’ clause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants