How do I cleanup the widget after it was deleted? #6346
-
|
In Here is an example: from textual import work
from textual.app import App
from textual.screen import Screen
from textual.widgets import Static, Footer
import aiohttp
class MyScreen(Screen):
def on_mount(self):
self.init()
@work
async def init(self):
self.session = aiohttp.ClientSession()
def compose(self):
yield Static('Now try quitting with ctrl+q and see the "Unclosed client session" warning')
class MyApp(App):
BINDINGS = [('a','push_screen("screen1")', "Open screen1")]
SCREENS = {
'screen1': MyScreen,
}
def compose(self):
yield Static("Press a")
yield Footer()
if __name__ == "__main__":
MyApp().run() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Ok, nevermind. I fixed this for switching screens by using on_screen_resume and on_screen_suspend events, and for quitting I simply did this in the on_quit function:
|
Beta Was this translation helpful? Give feedback.
Ok, nevermind. I fixed this for switching screens by using on_screen_resume and on_screen_suspend events, and for quitting I simply did this in the on_quit function: