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

implementations of the deprecated load_module import loader API, as prescribed by the documentation, are not thread safe #87824

Open
kale-smoothie mannequin opened this issue Mar 29, 2021 · 1 comment
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir topic-importlib type-bug An unexpected behavior, bug, or error

Comments

@kale-smoothie
Copy link
Mannequin

kale-smoothie mannequin commented Mar 29, 2021

BPO 43658
Nosy @kale-smoothie
Files
  • thread_unsafe_import.py: set env var PICK_API=N with N in {0,1} to demonstrate thread unsafe import and N=2 for expected behaviour
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2021-03-29.16:53:01.049>
    labels = ['type-bug', '3.8', '3.9', '3.10', '3.7', 'docs']
    title = 'implementations of the deprecated load_module import loader API, as prescribed by the documentation, are not thread safe'
    updated_at = <Date 2021-03-29.16:53:01.049>
    user = 'https://github.com/kale-smoothie'

    bugs.python.org fields:

    activity = <Date 2021-03-29.16:53:01.049>
    actor = 'kale-smoothie'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2021-03-29.16:53:01.049>
    creator = 'kale-smoothie'
    dependencies = []
    files = ['49916']
    hgrepos = []
    issue_num = 43658
    keywords = []
    message_count = 1.0
    messages = ['389713']
    nosy_count = 2.0
    nosy_names = ['docs@python', 'kale-smoothie']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43658'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    @kale-smoothie
    Copy link
    Mannequin Author

    kale-smoothie mannequin commented Mar 29, 2021

    Unless I've misread or misunderstood, the documentation at https://docs.python.org/3/reference/import.html#loaders for the deprecated load_module method doesn't indicate any requirements or caveats for thread safe importing. As it stands, I think it is not thread-safe, since the module is not protected against concurrent imports by the internal implementation marker __spec__._initializing = True.

    Additionally, the deprecated function decorator, importlib.util.module_for_loader seems to implement the marker incorrectly (sets __initializing__ directly on the module).

    I think this behaviour should either be documented as a major caveat, or internal details exposed to allow thread-safe implementations, or the old API removed entirely.

    @kale-smoothie kale-smoothie mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Mar 29, 2021
    @kale-smoothie kale-smoothie mannequin added docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Mar 29, 2021
    @kale-smoothie kale-smoothie mannequin added docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error labels Mar 29, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes docs Documentation in the Doc dir topic-importlib type-bug An unexpected behavior, bug, or error
    Projects
    Status: No status
    Development

    No branches or pull requests

    1 participant