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

Flet freezes when doing expensive task in a thread #3738

Open baseplate-admin opened 1 month ago

baseplate-admin commented 1 month ago

Duplicate Check

Describe the bug

So, as it stands. If i do something computationally expensive in a thread, it locks the main thread and thus the app freezes.

Code sample

https://github.com/coreproject-moe/CoreProject/tree/1a5eb12b15327bcc31e160d2985f07766b54538d/seeder

Problematic code


    def did_mount(self):
        self.page.run_task(self.fetch_all_people)

    async def fetch_all_people(self):
        builder = StaffBuilder()
        dictionary = builder.build_dictionary(sort=True)

        async with self.session() as _session:
            for i in dictionary:
                db_obs = Staff(mal_id=i)
                _session.add(db_obs)
            await _session.commit()

Source

To reproduce

  1. Copy the repository
  2. poetry install
  3. poetry run poe dev

Expected behavior

The Application should not freeze up

Screenshots / Videos

https://github.com/user-attachments/assets/1e3bf345-736d-440d-bd91-ab0bad8f43f1

Operating System

macOS

Operating system details

Windows 11

Flet version

0.23.2

Regression

No, it isn't

Suggestions

i think this could be because of either

Logs

None

Additional details

None

baseplate-admin commented 1 month ago

Hi, do you think flet should include support for multiproceesing? Preferably via dart coroutines