-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
[Bug]: plt.show(block=True) when a wx.App is already running #23072
Comments
I will defer to wx experts on if this is a good idea or not technically, I have grave concerns about this conceptually.
With With There is also Taken together I think using See https://matplotlib.org/stable/users/explain/interactive_guide.html for more writing on this. It is the case that Wx (and Qt) gives you a way to run a re-entrant event loop (so is the middle of processing a callback take a break and process other callbacks for a bit), I am not sure if this is general across all of the toolkits we support. All of this taken together, I am not an favor of changing this behavior. Given the example, I assume this is part of a much bigger UI application I would strongly suggest you go down path of using the explicit API + full embedding, rather than pyplot, and manage your windows yourself. I do not know what the other backends do in the analogous case. If they all do block in in the callback, then despite my concerns the behavior should match. |
Thanks ! FYI, my typical use case is detailed below:
However, because most users are not comfortable with command line,
(the design may be bad and it would maybe be better to execute the first script through subprocess) |
I would suggest the small modification to be something like: def process_interactive(file, *, blocking_function=None):
if blocking_function is None:
blocking_function = lambda : plt.show(block=True)
...
# your code
...
blocking_function()
return stuff so that way when you wrap it for the UI you can parameterize how to block to the context. |
Bug summary
When trying to use pyplot interface from wx.App, pyplot.show() does not block and does not start an event loop
Code for reproduction
Actual outcome
With the above code, the line
print("This shouldn't get printed before the closing the pyplot window!")
gets executed even though the pyplot window is not closed.
Expected outcome
The line should not be executed before the pyplot window is closed
Additional information
In backend_wx.py, mainloop() is testing for wx.App.IsMainloopRunning(), which is True, and does not go any further.
Not a fix, but calling
immediately after plt.show()
restores the blocking behaviour. Wondering if it is reliable or if this trick may break in a near future?
Operating system
Windows10
Matplotlib Version
3.4.3
Matplotlib Backend
WX; WXAgg
Python version
3.8.8
Jupyter version
not applicable
Installation
conda
The text was updated successfully, but these errors were encountered: