MAINT: mark evil_global_disable_warn_O4O8_flag as thread-local#26676
MAINT: mark evil_global_disable_warn_O4O8_flag as thread-local#26676seberg merged 1 commit intonumpy:mainfrom
Conversation
|
The Clang problem is fixed in main. |
rgommers
left a comment
There was a problem hiding this comment.
The variable name actually starts with evil :)
Seems simple enough, leaving open for a bit in case someone with more context about this flag wants to take a look.
|
Thanks LGTM.
Subinterpreters can be free-threaded, no? So it would have to be thread-local there also, I think? |
You're right, it would need to be a thread-local variable in the interpreter state struct. I don't even know if such a thing is possible. |
I also looked at getting rid of the flag entirely but unfortunately the pickle format encodes dtype="O" as "O8" on 64 bit systems, coming from this line:
numpy/numpy/_core/src/multiarray/descriptor.c
Line 2744 in 1854f26
Unfortunately we didn't change that to writing just "O" instead of "O4" or "O8" when we deprecated this and added the global flag back in 2012, so we need to keep the evil global flag. I have no idea if changing how object dtypes get written to pickle files would break other things or subtly break compatibility across numpy versions.
However, we can at least make the evil global flag thread safe by marking it as a thread-local variable, just like the promotion state.
If we ever wanted to support subinterpreters, we'd need to move this state into the module state and it would no longer need to be thread-local.
You could test this by having one thread load a pickle file and another thread create e.g. an "O4" dtype simultaneously. In practice it's tricky to actually write such a test because pytest isn't thread-safe, so I can't use e.g.
pytest.warnsinside a thread.