Author Stanisław Skonieczny (Uosiu)
Recipients Stanisław Skonieczny (Uosiu), Yoichi Nakayama, iritkatriel, michael.foord, pitrou
Date 2021-02-22.10:10:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CADp+y_GBe9VTsvFi7fCz6v6=_o60Zt4eMfJq31ywPdhpvze=7Q@mail.gmail.com>
In-reply-to <1613987755.89.0.931650465912.issue26600@roundup.psfhosted.org>
Content
When you just create a magick mock and then call `__str__` on it, it never
throws an exception and always return a string.
But... when you create a magick mock and then call `__str__` from two
threads concurrently, one of them will raise an exception.

Race is as follows:
1. Thread 1 creates magick mock m.
2. Thread 1 enters `m.__str__` it starts some internal preparations. It
does not exit `__str__` yet.
3. Thread 2 enters `m.__str__`.
In effect one of this threads will try to return `MagickMock` instance
instead of `str` object, which if forbidden by python.
Some low-level python check will raise following exception: `TypeError:
__str__ returned non-string (type MagicMock)`.

Stanisław Skonieczny

On Mon, Feb 22, 2021 at 10:56 AM Irit Katriel <report@bugs.python.org>
wrote:

>
> Irit Katriel <iritkatriel@yahoo.com> added the comment:
>
> Why is this only relevant to multiple thread?
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue26600>
> _______________________________________
>
History
Date User Action Args
2021-02-22 10:10:50Stanisław Skonieczny (Uosiu)setrecipients: + Stanisław Skonieczny (Uosiu), pitrou, michael.foord, Yoichi Nakayama, iritkatriel
2021-02-22 10:10:50Stanisław Skonieczny (Uosiu)linkissue26600 messages
2021-02-22 10:10:50Stanisław Skonieczny (Uosiu)create