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

Are celpy Environments thread safe? #38

Open
anteph opened this issue Dec 15, 2022 · 1 comment
Open

Are celpy Environments thread safe? #38

anteph opened this issue Dec 15, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@anteph
Copy link

anteph commented Dec 15, 2022

Hello!

I was wondering if a celpy Environment instance could be shared amongst threads, or if we should create a new instance when we want to create a runner for a new expression.

I tried to look through the docs and source code but didn't find any reference to this.

One thing I've noticed though is that, when we call the program method, the code is doing an intermediate assignment to an instance variable of the environment, before returning, which I believe can be problematic in terms of thread preemption.

        self.runnable = runner_class(self, expr, functions)
        return self.runnable

Nonetheless I might have missed something and would like to get your feedback on this use case.

Thank you very much!

@slott56
Copy link
Collaborator

slott56 commented May 20, 2024

There was no design intention to be thread-safe. There are no internal threads.

An example of using threading.local() to manage storage for an Environment instance would be helpful.

If a change is needed for thread-safety, please help with a scenario that we can use as an acceptance test case, perhaps a simple example that shows multiple threads.

@slott56 slott56 added question Further information is requested documentation Improvements or additions to documentation labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants