-
-
Notifications
You must be signed in to change notification settings - Fork 122
Fix __repr__ race (Free-Threaded)
#1328
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
a88589b
2f35d99
b545d5d
82558d3
0e801a4
907e6f4
95139ad
451ec47
c496c95
090f394
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fixed race when calling for a string representation of a ``MultiDict`` object. | ||
| -- by :user:`Vizonex` | ||
|
Vizonex marked this conversation as resolved.
Vizonex marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| import sysconfig | ||
| import textwrap | ||
|
|
||
| FREETHREADED = bool(sysconfig.get_config_var("Py_GIL_DISABLED")) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be moved to the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do also since we seem to have a ton of bugs to patch. I was thinking about a new module called
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's see if @Dreamsorcerer and @bdraco have opinions on this, then.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. :)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surely the tests should pass on regular versions of Python? |
||
|
|
||
|
|
||
| if __name__ == "__main__" and FREETHREADED: | ||
| child = textwrap.dedent(""" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| import signal, threading, time | ||
| signal.alarm(20) | ||
| from multidict import MultiDict | ||
| md = MultiDict([(f"k{i}", i) for i in range(50)]) | ||
| errors = [] | ||
| stop = threading.Event() | ||
| def repr_loop(): | ||
| while not stop.is_set(): | ||
| try: repr(md) | ||
| except Exception as e: errors.append(type(e).__name__) | ||
| def mutate_loop(): | ||
| i = 0 | ||
| while not stop.is_set(): md.add(f"m{i}", i); i += 1 | ||
| ts = [threading.Thread(target=repr_loop, daemon=True) for _ in range(2)] | ||
| ts += [threading.Thread(target=mutate_loop, daemon=True) for _ in range(2)] | ||
| for t in ts: t.start() | ||
| time.sleep(0.3); stop.set(); time.sleep(0.05) | ||
| print(f"repr errors: {len(errors)}") | ||
| """) | ||
| subprocess.run( | ||
| [sys.executable, "-c", child], | ||
| env={**os.environ, "PYTHON_GIL": "0"}, | ||
| capture_output=True, | ||
| timeout=60, | ||
| check=True, | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.