Fix __repr__ race (Free-Threaded)#1328
Conversation
__repr__ race (Free-Threaded)
| import sysconfig | ||
| import textwrap | ||
|
|
||
| FREETHREADED = bool(sysconfig.get_config_var("Py_GIL_DISABLED")) |
There was a problem hiding this comment.
I think this should be moved to the skipif mark in the pytest param.
There was a problem hiding this comment.
I do also since we seem to have a ton of bugs to patch. I was thinking about a new module called test_free_threaded.py when #1327 is merged to just have both of them in a new file.
There was a problem hiding this comment.
Let's see if @Dreamsorcerer and @bdraco have opinions on this, then.
There was a problem hiding this comment.
Surely the tests should pass on regular versions of Python?
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
|
|
||
|
|
||
| if __name__ == "__main__" and FREETHREADED: | ||
| child = textwrap.dedent(""" |
There was a problem hiding this comment.
I'd also get rid of the double-subprocess indirectly here. If we want to invoke a bunch of Python code with different Python flags, we can put those flags into the test parametrization. Additionally, a chunk of Python in a string is not lintable, and the coverage is not getting measured. It should definitely live in a Python module as a first-class citizen.
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
|
Thanks for tackling this @Vizonex. I think there's a lock-release bug in the current form, though: the critical section is opened at the top of On a free-threaded build that should deadlock as soon as the same object is # free-threaded build (Py_GIL_DISABLED), single thread is enough:
from multidict import MultiDict
md = MultiDict([("a", 1)])
repr(md) # success path returns WITHOUT Py_END_CRITICAL_SECTION -> md stays locked
repr(md) # re-enters Py_BEGIN_CRITICAL_SECTION(md) on the same thread -> hangsIf CI is green it's worth checking that |
@devdanzin The other maintainers and I are still debating on Free-Threaded support, while we don't necessary see a need for it to be included I'm glad your still keeping us going. I might return to this bug fix if I feel more encouragement though. There was also an idea to move to Rust (Pyo3) to stop a lot of these noticeable memory leaks and other related bugs but the probability of that happing is very small as I see rust hindering the current performance benefits. |
What do these changes do?
Fixes another race condition seen in https://gist.github.com/devdanzin/fa00e03ef041c030660f083116a7e1b6#7-repr-race--md_repr Item 7.
Are there changes in behavior for the user?
Related issue number
#1321
Checklist