-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
call to colorbar not thread safe #1889
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
Thanks for the report! Would you like to open a PR? I think you are the best placed to see if you proposed fixes solve the problem for you |
Hi, Yes why not even though I am not too familiar with the process. I am not even able to properly install the library so far ... |
You are lucky, we just added a contributing guide to xarray: http://xarray.pydata.org/en/latest/contributing.html ;-) The recommended way to install xarray (and any other local library btw) is:
|
thanks, got it. |
I agree that it is certainly a best practice to avoid relying on global state from the pyplot module. That said, my experience has been that even if you avoid using pyplot functions matplotlib is still not thread-safe (StackOverflow backs me up here). So you probably will need a thread-lock around your use of any plotting functions, anyways. |
Ok, thanks, do you have a piece of code with a thread-lock that I could get inspiration from? |
@apatlpo sure, something like: import threading
import matplotlib.pyplot
MPL_LOCK = threading.Lock()
def save_imshow(data, path):
with MPL_LOCK:
fig, ax = plt.subplot()
ax.imshow(data)
fig.savefig(path)
|
Closing for now. @apatlpo, feel free to reopen if there's more to discuss here. |
I reopen this issue as it came across my road again when generating figures on a dask.Distributed LocalCluster. |
hehe. I cannot reopen the issue apparently |
Another way to do this would be to use def plotfunc(da):
f = plt.figure()
...
f.close()
return da.time # or similar I have used this successfully with a distributed cluster. |
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here or remove the |
The following call in
xarray/xarray/plot/plot.py
does not seem to be thread safe:It leads to systematic crashes when distributed, with a cryptic error message (
ValueError: Unknown element o
). I have to call colorbars outside the xarray plot call to prevent crashes.A call of the following type may fix the problem:
But
fig
does not seem to be available directly in plot.py. Maybe:cheers
The text was updated successfully, but these errors were encountered: