Is it safe to use sympy in multi-threaded environment?

99 views
Skip to first unread message

Paul Royik

unread,
Aug 8, 2020, 11:09:20 AM8/8/20
to sympy
If a couple of users use sympy at the same time (like live.sympy.org), is it considered safe?
What about cache?

Oscar Benjamin

unread,
Aug 8, 2020, 12:22:26 PM8/8/20
to sympy
I don't know the inner workings of SymPy Live but I would imagine that
it uses a separate process for each user so that it isn't really
running SymPy in a multi-threaded environment.

On Sat, 8 Aug 2020 at 16:09, Paul Royik <distan...@gmail.com> wrote:
>
> If a couple of users use sympy at the same time (like live.sympy.org), is it considered safe?
> What about cache?
>
> --
> 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 sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/03913cb1-7348-4236-8c68-a83104713928o%40googlegroups.com.

Paul Royik

unread,
Aug 8, 2020, 4:32:32 PM8/8/20
to sympy
If sympy is run in multi-threaded environment, like apache, is it safe? Does cache require special handling?


On Saturday, August 8, 2020 at 7:22:26 PM UTC+3, Oscar wrote:
I don't know the inner workings of SymPy Live but I would imagine that
it uses a separate process for each user so that it isn't really
running SymPy in a multi-threaded environment.

On Sat, 8 Aug 2020 at 16:09, Paul Royik <distan...@gmail.com> wrote:
>
> If a couple of users use sympy at the same time (like live.sympy.org), is it considered safe?
> What about cache?
>
> --
> 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 sy...@googlegroups.com.

Aaron Meurer

unread,
Aug 8, 2020, 4:51:13 PM8/8/20
to sympy
I wouldn't recommend using threads with SymPy. Even if it works (which
I expect it won't because we do have global things like the cache),
the Python GIL would prevent it from truly working concurrently.
Instead, use different processes.

Aaron Meurer
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/469ffd55-50ce-4261-a763-eb20a248b81do%40googlegroups.com.

Paul Royik

unread,
Aug 9, 2020, 3:14:30 PM8/9/20
to sympy
Thank you.


On Saturday, August 8, 2020 at 11:51:13 PM UTC+3, Aaron Meurer wrote:
I wouldn't recommend using threads with SymPy. Even if it works (which
I expect it won't because we do have global things like the cache),
the Python GIL would prevent it from truly working concurrently.
Instead, use different processes.

Aaron Meurer

On Sat, Aug 8, 2020 at 2:32 PM Paul Royik <distan...@gmail.com> wrote:
>
> If sympy is run in multi-threaded environment, like apache, is it safe? Does cache require special handling?
>
> On Saturday, August 8, 2020 at 7:22:26 PM UTC+3, Oscar wrote:
>>
>> I don't know the inner workings of SymPy Live but I would imagine that
>> it uses a separate process for each user so that it isn't really
>> running SymPy in a multi-threaded environment.
>>
>> On Sat, 8 Aug 2020 at 16:09, Paul Royik <distan...@gmail.com> wrote:
>> >
>> > If a couple of users use sympy at the same time (like live.sympy.org), is it considered safe?
>> > What about cache?
>> >
>> > --
>> > 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 sy...@googlegroups.com.
>> > To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/03913cb1-7348-4236-8c68-a83104713928o%40googlegroups.com.
>
> --
> 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 sy...@googlegroups.com.
Message has been deleted

Paul Royik

unread,
Aug 12, 2020, 6:39:47 AM8/12/20
to sympy
Can SymPy run inside a Celery task?


On Saturday, August 8, 2020 at 11:51:13 PM UTC+3, Aaron Meurer wrote:
I wouldn't recommend using threads with SymPy. Even if it works (which
I expect it won't because we do have global things like the cache),
the Python GIL would prevent it from truly working concurrently.
Instead, use different processes.

Aaron Meurer

On Sat, Aug 8, 2020 at 2:32 PM Paul Royik <distan...@gmail.com> wrote:
>
> If sympy is run in multi-threaded environment, like apache, is it safe? Does cache require special handling?
>
> On Saturday, August 8, 2020 at 7:22:26 PM UTC+3, Oscar wrote:
>>
>> I don't know the inner workings of SymPy Live but I would imagine that
>> it uses a separate process for each user so that it isn't really
>> running SymPy in a multi-threaded environment.
>>
>> On Sat, 8 Aug 2020 at 16:09, Paul Royik <distan...@gmail.com> wrote:
>> >
>> > If a couple of users use sympy at the same time (like live.sympy.org), is it considered safe?
>> > What about cache?
>> >
>> > --
>> > 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 sy...@googlegroups.com.
>> > To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/03913cb1-7348-4236-8c68-a83104713928o%40googlegroups.com.
>
> --
> 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 sy...@googlegroups.com.

Aaron Meurer

unread,
Aug 12, 2020, 4:04:24 PM8/12/20
to sympy
I haven't tried it but I imagine it would. The biggest challenge would
be the serialization method. SymPy can have issues with things like
pickle sometimes.

Aaron Meurer
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/acca8510-3144-40b8-9456-866ab17932dco%40googlegroups.com.
Message has been deleted
Message has been deleted

Paul Royik

unread,
Aug 13, 2020, 4:52:11 PM8/13/20
to sympy
You're right with a serialization.

But Celery uses threads. Will it be safe? Or does it use only processes?

roberto franceschini

unread,
Aug 14, 2020, 3:34:37 AM8/14/20
to sy...@googlegroups.com
> SymPy can have issues with things like pickle sometimes.

Such as?

On Thu, Aug 13, 2020 at 10:49 PM Paul Royik <distan...@gmail.com> wrote:
You're right.

--
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 sympy+un...@googlegroups.com.

Aaron Meurer

unread,
Aug 19, 2020, 6:26:05 PM8/19/20
to sympy
The most common culprit is undefined Function objects, like
Function('f'). This currently dynamically creates a class, which means
that pickle cannot easily handle it. If you use something like
cloudpickle, it can handle it better. However, I've also had issues
even with cloudpickle before. For example, this bug happens with both
pickle and cloudpickle:

>>> Float(pi, dps=100)
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
>>> pickle.loads(pickle.dumps(Float(pi, dps=100)))
3.141592653589793115997963468544185161590576171875000000000000000000000000000000000000000000000000000

We need to make a concerted effort to make SymPy expressions serialize
better and get rid of the bugs with it.

Aaron Meurer
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAJxM9JqSRBqzYbfMYJsq3ZG9M4N5F0FiYps4-gi8VW32R8b4%3Dg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages