-
Notifications
You must be signed in to change notification settings - Fork 14
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
Ship free-threaded wheels #101
Comments
Correct.
Yes that was my understanding as well, though I did less work than it sounds like you did already to check how well this is tested in rpds itself.
I like your Said more "brutally", I'm personally OK with letting someone tell us if it turns out there are thread safety issues. (And again sincere thanks for all the help so far and for the work you're doing more broadly!) |
OK great, I'll keep the hypothesis idea on the backburner, I don't think I want to take on setting up hypothesis to do that since I've never set up hypothesis from scratch, let alone in a multithreaded context. That said, I bet we could leverage hypothesis to make it easier to productively start from scratch on writing multithreaded tests for sharing data structures here and in many other packages. I'll bring this up at our next internal sync on our ecosystem compatibility team. |
Hm, while I love |
Yup, ran into that elsewhere today in the python-zstandard test suite. |
I'm seeing test failures on Linux if I run the tests with The failures look like:
I can reproduce this on my Ubuntu 22.04 developer machine using a pyenv-built 3.13.0t and the python-build-standalone python3.13t that The error is coming from CPython internals and sort of looks like some sort of thread safety issue in PyO3. |
Oh actually I wonder if this is hitting the thread-safety issues in |
No, I still see if it I build Python using the latest version of the CPython 3.13 branch. Some more info: The errors are coming from the rpds/tests/test_hash_trie_map.py Lines 364 to 380 in 2597aa4
And here's what the call stack looks like from inside gdb - somehow a corrupt PyObject struct is being passed into Ping @davidhewitt and @colesbury in case this rings any bells as a PyO3 or CPython bug related to collections.abc protocols. I'm going to see if I can make a small reproducer using only PyO3 tomorrow. |
No, sorry, doesn't ring any bells. For what it's worth, it looks to me like the error happens during the execution of |
I can trigger this issue if I build a free-threaded wheel using the current from operator import methodcaller
from concurrent.futures import ThreadPoolExecutor
from rpds import HashTrieMap
num_workers=1000
views = [methodcaller(p) for p in ["keys", "values", "items"]]
def work(view):
m, d = HashTrieMap(), {}
view(m)
view(d)
iterations = 10
for _ in range(iterations):
executor = ThreadPoolExecutor(max_workers=num_workers)
for view in views:
futures = [executor.submit(work, view) for _ in range(num_workers)]
results = [future.result() for future in futures] Notably it doesn't happen if def work(view):
m = HashTrieMap()
view(m) So it looks like |
Also worth noting that if I insert a |
I think I was able to reproduce this in just pure Python (using a modification of your code). So I think it's a bug in CPython, not PyO3 or rpds: https://gist.github.com/colesbury/0d3fa451b4b47e661952d2a1b88be461 Once every 5-10 runs, I get:
|
OK, in that case I think we're OK to move forward with a PR setting up |
...except it looks like I'll need to do some work in maturin to make it possible to build free-threaded wheels:
|
My real goal with #100 was to enable shipping free-threaded wheels. I'm actively working on improving the state of free-threaded support for popular packages on PyPI and this package is one of them. I'll be linking to this issue from https://py-free-threading.github.io/tracking/. See that website for lots more information on supporting free-threaded Python.
Looking at the existing tests, they don't use the python
threading
module at all and there aren't any rust-level tests. Is that correct?One thing we could try without writing tests for explicit multithreaded use is running
pytest-run-parallel
on the full test suite. That wouldn't catch thread safety issues caused by sharing data structures provided by rpds between threads, but it would catch issues due to use of global state.I see this library already uses
new_sync
to create the rpds data structures, so according to the rpds docs everything should be thread safe. Do you agree with that assessment?But also I don't actually see any multithreaded tests in the rust rpds library itself, so I'm not sure how carefully validated that is besides the fact that cargo parallelizes tests automatically.
Do you have any ideas for ways to validate the thread safety of the python library before we upload wheels and declare the
rpds
module is thread-safe?The text was updated successfully, but these errors were encountered: