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

AttributeError: Can't get attribute 'initializer' on <module 'loky.backend.popen_loky_posix' ... #146

Closed
vvvhung opened this issue Aug 14, 2018 · 3 comments

Comments

@vvvhung
Copy link

vvvhung commented Aug 14, 2018

I run example at https://loky.readthedocs.io/en/stable/auto_examples/reuseable_executor.html#sphx-glr-download-auto-examples-reuseable-executor-py but error occur

--------------------------------------------------------------------------------
LokyProcess-2 failed with traceback: 
--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/louis/Documents/venv_flax_py3/lib/python3.6/site-packages/loky/backend/popen_loky_posix.py", line 198, in <module>
    process_obj = pickle.load(from_parent)
AttributeError: Can't get attribute 'initializer' on <module 'loky.backend.popen_loky_posix' from '/Users/louis/Documents/venv_flax_py3/lib/python3.6/site-packages/loky/backend/popen_loky_posix.py'>


--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
LokyProcess-1 failed with traceback: 
--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/louis/Documents/venv_flax_py3/lib/python3.6/site-packages/loky/backend/popen_loky_posix.py", line 198, in <module>
    process_obj = pickle.load(from_parent)
AttributeError: Can't get attribute 'initializer' on <module 'loky.backend.popen_loky_posix' from '/Users/louis/Documents/venv_flax_py3/lib/python3.6/site-packages/loky/backend/popen_loky_posix.py'>


--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/louis/Documents/test/scripts/multi_loky.py", line 31, in <module>
    assert executor.submit(test_initializer).result() == 'initialized'
  File "/Users/louis/Documents/venv_flax_py3/lib/python3.6/site-packages/loky/_base.py", line 431, in result
    return self.__get_result()
  File "/Users/louis/Documents/venv_flax_py3/lib/python3.6/site-packages/loky/_base.py", line 382, in __get_result
    raise self._exception
loky.process_executor.BrokenProcessPool: A process in the executor was terminated abruptly while the future was running or pending.
@tomMoral
Copy link
Collaborator

Thanks for reporting this.
I can indeed reproduce. Here, the initializer is not picklable as the main module is not initialized. It would need to be serialized with cloudpickle.

@vvvhung
Copy link
Author

vvvhung commented Aug 15, 2018

It will be great if we have a trick to overcome it right now. Thank you.

@tomMoral
Copy link
Collaborator

A quick fix would be to use the following script, and launch it with the environment variable LOKY_PICKLER='pickle'.

from time import sleep
from loky import get_reusable_executor


INITIALIZER_STATUS = 'uninitialized'


def initializer(x):
    global INITIALIZER_STATUS
    INITIALIZER_STATUS = x


def return_initializer_status(delay=0):
    sleep(delay)

    global INITIALIZER_STATUS
    return INITIALIZER_STATUS


if __name__ == '__main__':
    executor = get_reusable_executor(
        max_workers=2, initializer=initializer, initargs=('initialized',),
        context="loky_init_main")

    assert executor.submit(return_initializer_status).result() == 'initialized'

    # With reuse=True, the executor use the same initializer
    executor = get_reusable_executor(max_workers=4, reuse=True)
    for x in executor.map(return_initializer_status, [.5] * 4):
        assert x == 'initialized'

    # With reuse='auto', the initializer is not used anymore as a new executor
    # is created.
    executor = get_reusable_executor(max_workers=4, context='loky_init_main')
    for x in executor.map(return_initializer_status, [.1] * 4):
        assert x == 'uninitialized'

After investigating, the issue here is that we do not handle consistently the pickling of the initializer in loky. The fix is non-trivial as it is linked to cloudpipe/cloudpickle#187.

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