-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Thread-safety in xarray #9836
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
Comments
My hope would be that pandas can fix this thread-safety issue upstream. Hopefully they are more amenable to doing so now (in 2025) than they were in 2013. |
In a thread where x3 = xr.merge(x1, x2) why do I hit the above issue? The actual message I get: |
if that's the whole program, and there are no other threads, you shouldn't hit an issue if that's running in a thread pool or similar, then you can get that sort of problem... (and iirc that is a message you would get...) |
Yes, this is within threadpool.starmap, x1 and x2 passed as parameters |
What's the workaround? |
those sound like reasonable things to try! I'm not confident on the solution unfortunately |
Uh oh!
There was an error while loading. Please reload this page.
What is your issue?
There's a process that can't use xarray because it's a multithreaded context, and xarray objects aren't thread-safe, because pandas indexes aren't thread-safe pandas-dev/pandas#2728
I did some quite exploration on where the issue was. I don't have a clear answer but thought it would be worthwhile to post some results.
Here's a function that tests a few operations:
The results:
A couple of things to note:
.sel
operations seemed to pass, most.reindex
operations seem to failx.reindex(dim_0=idx.copy())
fails, but runningx.sel(dim_0=idx)
beforehand makes the initial.reindex
pass (?!)x.reindex(dim_0=x.dim_0)
works, but not with an index that's passed in,x.reindex(dim_0=idx)
. (Could we claim that when xarray objects are accessed by different threads, they're safe? I'd be surprised if that were the case, but couldn't immediately see a case where that was falsified...)I don't think there are any easy answers to this; if we wanted xarray / parts of xarray to be threadsafe. I think it's a bunch of bad options:
The text was updated successfully, but these errors were encountered: