flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
10.86k stars 417 forks source link

Closing the program takes too long #3918

Open icsos opened 1 week ago

icsos commented 1 week ago

Duplicate Check

Describe the bug

In the official code, when I click 'yes' to close the program, it takes 3-5 seconds.

Code sample

https://flet.dev/docs/controls/page/#window_destroy

import flet as ft

def main(page: ft.Page):
    page.title = "MyApp"

    def handle_window_event(e):
        if e.data == "close":
            page.open(confirm_dialog)

    page.window.prevent_close = True
    page.window.on_event = handle_window_event

    def handle_yes(e):
        page.window.destroy()

    def handle_no(e):
        page.close(confirm_dialog)

    confirm_dialog = ft.AlertDialog(
        modal=True,
        title=ft.Text("Please confirm"),
        content=ft.Text("Do you really want to exit this app?"),
        actions=[
            ft.ElevatedButton("Yes", on_click=handle_yes),
            ft.OutlinedButton("No", on_click=handle_no),
        ],
        actions_alignment=ft.MainAxisAlignment.END,
    )

    page.add(ft.Text('Try exiting this app by clicking window\'s "Close" button!'))

ft.app(main)

To reproduce

  1. Run the repro code
  2. Click on close, and yes

Expected behavior

No response

Screenshots / Videos

Captures [Upload media here]

Operating System

Windows

Operating system details

Windows 10

Flet version

0.24.0

Regression

No, it isn't

Suggestions

No response

Logs

Logs ```console [Paste your logs here] ```

Additional details

No response

ndonkoHenri commented 1 week ago

Works normally on macOS. Can any Windows user test this and report?

Also, @icsos, does this issue happen occasionally or always.

lixxu commented 1 week ago

same on Windows 11 and 0.24

lixxu commented 1 week ago

Works normally on macOS. Can any Windows user test this and report?

Also, @icsos, does this issue happen occasionally or always.

tested on Windows 11, it happens always (about 5~6 seconds to quit). I use below ugly way to prevent this:

#page.window.destroy()
page.close(confirm_dialog)
page.window.prevent_close = False
page.window.close()
nastiliano commented 1 week ago

Hello,

In my Linux (Mint 22 , Cinamon 6.2.9) with v.024.1 closes acceptable (about 1.5 seconds), but appears a Warning Message:

image

nastiliano commented 1 week ago

Works normally on macOS. Can any Windows user test this and report? Also, @icsos, does this issue happen occasionally or always.

tested on Windows 11, it happens always (about 5~6 seconds to quit). I use below ugly way to prevent this:

#page.window.destroy()
page.close(confirm_dialog)
page.window.prevent_close = False
page.window.close()

Hello,

Just now, tested on Windows 11 x64 (completly updated) with last Flet version (v.0.24.1).

It has been enhanced. At least for me. It takes about 1.5 seconds to close (acceptable) without errors.

Thanks. Best regards.

nastiliano commented 1 week ago

Works normally on macOS. Can any Windows user test this and report?

Also, @icsos, does this issue happen occasionally or always.

Hello,

Just now tested with v.024.1 on MacOS updated (Sonoma 14.6.1 - Intel Processor).

The app closes perfectly and fast. (faster than Windows. 0 seconds :)

Thanks. Best regards

ndonkoHenri commented 1 week ago

Just now, tested on Windows 11 x64 (completly updated) with last Flet version (v.0.24.1). It has been enhanced. At least for me.

@icsos @lixxu, please upgrade your Flet version an retry.

lixxu commented 1 week ago

tried and takes longer time... updated: tried many times, and it will take about 10s to quit. explorer_gZOaDI76hB image