-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FigureCanvasTkAgg.draw() silently crashes in threaded application #13293
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
Matplotlib makes no guarantees of thread safety. You'll need to use other methods to ensure that only one thread accesses it (conditions, mutexes, GUI-specific signals (if available), etc.) |
Even though we do not claim that Matplotlib is threadsafe, there is no obvious race here and the sefault is coming from inside Lines 212 to 250 in 5a53f5e
We may also be hitting non-thread safe operations in tk? |
You can get a backtrace via
Looking upstream at this comment, there does appear to be some queuing involved and using the interpreter across threads is risky. Our Also according to a later comment, Tk may or may not be compiled with thread support. |
I also have this problem, calling everything from the same thread. |
AFAICT this is simply not supported by Tcl. Per http://www.tcl.tk/doc/howto/thread_model.html:
We could start peppering the codebase with So I'll close as wontfix, but as usual feel free to disagree and reopen... |
@xzores Is that thread the main thread? In general GUI toolkits do not like having any part of them be run in a background thread (unless they manage it). |
No it is in an other thread, but it is the same thread |
I can't do "if threading.current_thread() == threading.main_thread()", because the main thread is used for tk.mainloop(). |
and I agree with the "can't fix" label, getting into thread safetly is starting to get into application logic and I suspect that any attempts on our part would invariably conflict with user's attempts to do the same in their application. |
Use Tk's signaling system to ask the main thread to schedule a draw. [edit to fix spelling] |
I get some data from the network, that I need to append to the existing data and update the plot |
Calling figure.canvas.draw() crashes my app, no exceptions thrown (that must be a bug) |
I've actually been working on this for some time. Since everyone seems to be looking at this right now, I've made a PR (#18565) to discuss. In short, we can use the tkinter cross-thread signaling to make draw and blit thread "safe" but Tk_photoputblock is fundamentally not parallelizable, so this only really prevents crashes. |
Bug report
Bug summary
Matplotlib crashes python without rising any exceptions (python simply closes), when draw method is called on FigureCanvasTkAgg object in threaded application from thread other than main thread.
Code for reproduction
Actual outcome
When button from example shown above is clicked, application window freezes for a moment and than closes along with python, no exception or error is displayed.
Expected outcome
Preferably draw method should run normally, or at least an exception should be rised.
In Matplotlib 2.2.2 same code snipped runs flawlessly.
Matplotlib version
print(matplotlib.get_backend())
): TkAggMatplotlib installed with 'pip install matplotlib'.
The text was updated successfully, but these errors were encountered: