Bug summary
I'm working on fixing several bugs with the macOS backend. I am trying to understand how show(), start_event_loop(), and stop_event_loop() should interact with each other.
I had several questions that I couldn't find in the documentation:
- If
show(block=True) is called, should stop_event_loop() make it return?
- If
start_event_loop() is called on a figure, should closing all windows make it return?
- What should be the behavior if
start_event_loop() or show(block=True) is called when an event loop is already running from show() or another start_event_loop()?
- If
stop_event_loop() is called without an event loop running, it appears to be a no-op across all backends. Should it instead throw an exception?
I wrote the attached code to test these. However, I am seeing different results from different backends. See charts in the "Actual Results" section.
Code for reproduction
import matplotlib.pyplot as plt
import matplotlib
import sys
example_index = int(sys.argv[1])
backend, mode = (
( "QtAgg", "show" ),
( "TkAgg", "show" ),
( "macosx", "show" ),
( "QtAgg", "start_event_loop" ),
( "TkAgg", "start_event_loop" ),
( "macosx", "start_event_loop" ),
)[ example_index ]
print(f"backend = '{backend}', mode = '{mode}'")
matplotlib.use(backend)
fig, ax = plt.subplots()
ax.set_title("Click anywhere to continue")
ax.plot([1, 2, 3])
clicked = []
def on_click(event):
clicked.append((event.xdata, event.ydata))
print("on_click")
fig.canvas.stop_event_loop()
fig.canvas.mpl_connect('button_press_event', on_click)
fig, ax = plt.subplots()
if (mode == "show"):
plt.show()
else:
plt.show(block=False)
fig.canvas.start_event_loop()
if (len(clicked) > 0):
print(f"User clicked at: {clicked[0]}")
else:
print(f"Event loop stopped without click")
Actual outcome
Does closing both windows stop the event loop?
backend |
mode |
Result |
| QtAgg |
show |
Yes |
| TkAgg |
show |
Yes |
| macosx |
show |
Yes |
| QtAgg |
start_event_loop |
No |
| TkAgg |
start_event_loop |
Yes |
| macosx |
start_event_loop |
No |
Does clicking on Figure 1 stop the event loop?
backend |
mode |
Result |
| QtAgg |
show |
No |
| TkAgg |
show |
Yes |
| macosx |
show |
No |
| QtAgg |
start_event_loop |
Yes |
| TkAgg |
start_event_loop |
Yes |
| macosx |
start_event_loop |
Yes |
Expected outcome
All backends should operate with the same behavior.
Additional information
No response
Operating system
No response
Matplotlib Version
Dev
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None
Bug summary
I'm working on fixing several bugs with the macOS backend. I am trying to understand how
show(),start_event_loop(), andstop_event_loop()should interact with each other.I had several questions that I couldn't find in the documentation:
show(block=True)is called, shouldstop_event_loop()make it return?start_event_loop()is called on a figure, should closing all windows make it return?start_event_loop()orshow(block=True)is called when an event loop is already running fromshow()or anotherstart_event_loop()?stop_event_loop()is called without an event loop running, it appears to be a no-op across all backends. Should it instead throw an exception?I wrote the attached code to test these. However, I am seeing different results from different backends. See charts in the "Actual Results" section.
Code for reproduction
Actual outcome
Does closing both windows stop the event loop?
backendmodeDoes clicking on Figure 1 stop the event loop?
backendmodeExpected outcome
All backends should operate with the same behavior.
Additional information
No response
Operating system
No response
Matplotlib Version
Dev
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None