On Sat, 1 Aug 2020 at 18:40, Paul Royik <[email protected]> wrote:
>
> In sympy.core.parameters it is written that "WARNING! Although the global 
> parameters are thread-local, SymPy's cache is not by now. This may lead to 
> undesired result in multi-threading operations."
> But in code I see
>
> def __setattr__(self, name, value):
>     if getattr(self, name) != value:
>         clear_cache()
>     return super().__setattr__(name, value)
>
>
> So, does this workaround help to use this feature safely?

It possibly helps but it isn't really thread-safe. The problem is that
there isn't a single cache, there are many little caches and clearing
them all can take some time and is not atomic. If you have two threads
using the same cache but with different settings for the global
parameters then one thread might insert items into the cache while
another is clearing the cache. By the time clear_cache finishes the
cache might not actually be empty.

To make the cache properly thread-safe in a situation where threads
can independently alter the global parameters there needs to be a
separate cache for each thread.

Personally I think that the ultimate fix is the elimination of all
global parameters. That's not easy but it's what we should aim for.

--
Oscar

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxSNmCQtFai%3DuVLY0D-iSr5BFA%2B1t%2B4%3DBUH-6VXjRcD%2BZg%40mail.gmail.com.

Reply via email to