flet icon indicating copy to clipboard operation
flet copied to clipboard

Excessive restart with `flet run` , restart race can occur

Open auphof opened this issue 1 year ago • 0 comments

Issue Description:

when i attempt to auto reload with flet run -d ./app --recursive a restart race commences when a file is modified or opened in a subdir below ./app . Even without --recursive file opens in ./app trigger a restart/reload

Environment

  1. Flet version: 0.22.0
  2. WSL2 with ubuntu 22.04
  3. IDE VSCODE v1.881
  4. HOST: Windows 11 on a modification in recursive

Steps to Reproduce:

following setup

# -------------------------------------------------------- 
# Example_app folder tree view
# --------------------------------------------
# example_app
# ├── .gitignore
# └── app
#     ├── __init__.py
#     ├── main.py
#     └── components
#                ├── my_flet_controls.py
#                └── __init__.py

Now cd example_app and then execute the app with flet run -d ./app --recursive modify /components/my_flet_controls.py in your ide and save will trigger a restart race. additionally just cat ./app/components/__init__.py will trigger a restart

with flet run -d ./app (NO --recursive) just a cat ./app/__init__.py will trigger a restart

Fix

in the flet run cli, Only restart if the watchdog event.event_type in ['modified','deleted','created','moved'] the handler is here https://github.com/flet-dev/flet/blob/a7d7c86930fe70550589c9ba665997c440980f51/sdk/python/packages/flet/src/flet/cli/commands/run.py#L291C12-L291C69

I will raise a PR for this

auphof avatar Apr 25 '24 09:04 auphof