Closed darrenburns closed 2 days ago
So, your example is "press a key twice and crash with 'TypeError: object NoneType...`on the self.dismiss()?
To clarify, you can remove all the Select
controls.
The issue is using await
on a non-async call. Instead of await self.dismiss()
, just use self.dismiss()
.
Yeah, the example is actually Will's edit :)
Sorry, this issue is kind of confusing and without context, as it was a quick note I made for Will based on something we discussed last week.
The issue is that key events get sent to non-active screens for a short period, before the screen has been completely dismissed. Most people won't expect this and may be doing things in their code which assumes the screen is active - leading to crashes.
The claimed sequence is:
self.dismiss()
is called and returns. on_key()
handler is called inside the dismissed screenSo, something more like:
def do_dismiss():
self.in_dismissal = True
self.dismiss()
def on_key(self):
if self.in_dismissal:
print("Error")
Then on a mouse move or timer, dismiss the window and pop it back, while pounding the keyboard and we should eventually hit "error"?
The original issue was a deadlock which tripped deadlock detection. That no longer occurs, because we removed the deadlock detection after improving the way widgets are removed. However the deadlock remains in the above code.
Essentially, the call to await dismiss()
on the screen was awaiting for itself to be removed. The solution would be to not await it, but that it's not great developer experience. I think either we report a helpful error, or make it work somehow. I'm working on that at the moment.
There is some other behavior that might need explaining, because it confused me initially. When you press a key on MyScreen
, both on_key
methods fire. This is because the event bubbles to the App. Obvious in retrospect.
Hopefully this is clear...
Don't forget to star the repository!
Follow @textualizeio for Textual updates.
Key events get sent to non-active screens for a short period on calling
dismiss
, before the screen has been completely dismissed. Most people won't expect this and may be doing things in their code which assumes the screen is active - leading to crashes.We should ensure key events are only delivered to the screen while it remains active.
Edit: