Skip to content

pymc3.model.Context is not thread-safe #1552

Closed
@burnpanck

Description

@burnpanck

When I first saw the context manager redesign in PyMC3 of what was a module level global in PyMC2, I welcomed this as a step forward in library compatibility by not relying on global state. However, the implementation is in fact the opposite: It relies on hidden global state, making the situation worse: The context manager suggests that the global activation of the model is scoped to the code within the context manager, but in fact it is global, only scoped in time! While for the average interactive statistician, this will probably not be much of a problem, but it makes the incorporation of PyMC3(-models) into libraries difficult, because a library should never modify global state.

I think the solution is simple: Context should use thread-local storage to store it's active model stack, however, I am just discovering PyMC3, so I could be missing something. Still, unless there are objections by more seasoned developers, I'd volunteer to write a PR for this.

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