Repository navigation
BUG: Make argmap._lazy_compile thread-safe - #8659
Conversation
|
This looks very promising!! -- Thanks @mridul!! Of course, when I run the test on a vanilla clone of the repo using a recent mamba environment that has nothing to do with threading, I don't get any error even after running it many times. So I have a question about how we can/will test threading based bugs and suggestions. What is the current CI setup for this? Do we have a freethreaded CI run? Should we? |
|
That's what we get for diving down into the dunders 🙃 - no thread-safety guarantees down there!
Interesting - the reproducer works every time on my machine - here's what I'm doing:
I wonder if there's a relationship between
Great question - I'd like to understand the full chain that results in this exception better. The good news is I'd expect that the thread-safety guarantees of Python itself are good enough for all code where we're not explicitly injecting into/overriding the object model, which should be the vast majority of the library.
We do - they are the runs with |
To answer my own question - there sure seems to be, at least on my machine! I tried on my m2 (10 cores) with varying values for Whether this result generalizes (and how it maps to CI, where threading/num_cpu detection is even weirder) - who knows! One easy thing to try: add the test first (without the fix) in it's own PR and twist the knobs on the parameters until we get it reliably failing on main. Ad-hoc is better than nothing! |
| func.__code__ = real_func.__code__ | ||
| func.__globals__.update(real_func.__globals__) | ||
| func.__dict__.update(real_func.__dict__) | ||
| with argmap._compile_lock: |
There was a problem hiding this comment.
Should we call this "lazy compile lock"?
Also, is it possible that the compile acquires the lock and causes a deadlock? I guess no but that's what also motivates my first question.
There was a problem hiding this comment.
Also, is it possible that the compile acquires the lock and causes a deadlock? I guess no but that's what also motivates my first question.
I am not a 100% sure honestly, this seemed like the easiest lock to put in to make the MRE happy. But I think for now we should try to get this merged and we can iterate on this in the future.
I went ahead and tried this over in #8676 - as we can see from the action logs this test doesn't fail as-is on CI for the 314t jobs; at least not reliably. FTR the test still fails locally every time for me on various (up to 16CPU/32thread) systems; so it's something to do with how threading behaves on the cloud (which doesn't surprise me). IMO the fix should go in for v3.7, regardless of test behavior in the action runners! I'm going to experiment a little more - some obvious things to try:
|
dschult
left a comment
There was a problem hiding this comment.
I've successfully gotten the error to occur locally (and consistently) on main. And the error does not occur locally consistently on this PR branch. I agree with the approach of merging this even if we don't see a difference on CI (passes on main and this branch).
My understanding is that we will next look for an example that breaks on CI. But that's really more about finding tests for future troubles than this PR anyway.
I approve this PR
fixes #8658
This adds a class level lock while moving over the code to the compiled version.
Disclaimer: Claude was used to create the following MRE, it is still stochastic but I was able to get it to fail pretty quickly.