dubovikmaster/parallelbar

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

Opened this issue · 2 comments

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/python@3.10/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/python@3.10/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/python@3.10/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/python@3.10/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/python@3.10/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/python@3.10/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/python@3.10/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/python@3.10/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/python@3.10/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/python@3.10/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/python@3.10/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/python@3.10/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...

Command line ipython gives the same error.

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