Skip to content

_is_dynamic fails on submodule in .so file #354

Closed

Description

@henryiii

When _is_dynamic checks a module, it only looks for the __spec__ and __file__ of the module being checked, and if that is not defined, it looks for the __path__ on the module above. For a PyBind11 module with a submodule, the __file__ is defined on the main module, but not submodules, and there is no __path__. So things in submodules cannot be cloudpickled.

I think the function should be recursively checking up the the module path, and shouldn't try to access parent.__path__ without a check or try.

Activity

  1. henryiii commented on Mar 26, 2020

    @henryiii
    Author

    Ref: scikit-hep/boost-histogram#342 . There, boost_histogram._core.hist is a submodule in boost_histogram/_core.so. Since hist is a submodule, it checks boost_histogram._core.__path__ which does not exist, though boost_histogram._core.__file__ does. (though you may need to go up further if this is a nested submodule).

  2. henryiii commented on Mar 26, 2020

    @henryiii
    Author

    (It might be that PyBind11 should set __file__ on submodules) Nevermind, setting this in C++ causes a segfault.

  3. pierreglaser commented on Mar 26, 2020

    @pierreglaser
    Member

    Thanks for reporting. I'll work on a fix ASAP. If you know of a good way to fix this, feel free to submit a PR. I'm not an expert of the Python import machinery.

  4. henryiii commented on Mar 28, 2020

    @henryiii
    Author

    I don't want to break dynamic modules. Can a dynamic module be nested inside a normal one? If not, this is an easy fix. And what's an example of a dynamic module?

  5. pierreglaser commented on Mar 28, 2020

    @pierreglaser
    Member

    We have tests that should cover the pickling of dynamic modules, so if your fix breaks the picking of dynamic module, the CI will let us know. I’m not quite sure what you mean by “nested dynamic modules”. Feel free to add any unit test that you think is relevant alongside your fix :)

  6. pierreglaser commented on Mar 31, 2020

    @pierreglaser
    Member

    Nevermind, setting this in C++ causes a segfault.

    Out of curiosity, are you using the C/Python API to do such an operation?

  7. henryiii commented on Mar 31, 2020

    @henryiii
    Author

    Yes; the PyBind11 API which is just a wrapper around the CPython API. Not sure where the crash came from, __file__ might not have been set yet.

  8. added a commit that references this issue on Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions