forked from Samagra-Development/ai-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch_folder.py
35 lines (27 loc) · 889 Bytes
/
watch_folder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from watchgod import awatch
# flag to avoid multiple watch_task running at the same time
watch_task_running = False
async def restart_quart(app):
"""
Restart the Quart application.
Parameters:
- app: The Quart application instance to restart.
"""
print("Reloading Quart...")
await app.shutdown()
await app.startup()
print("Quart reloaded.")
async def watch_src_folder(app, watch_dir):
"""
Monitor changes in the 'src' folder and restart Quart on change.
Parameters:
- app: The Quart application instance to monitor and restart.
- watch_dir: The path to the directory to monitor for changes.
"""
global watch_task_running
if watch_task_running or not app.debug:
return
watch_task_running = True
async for changes in awatch(watch_dir):
await restart_quart(app)
watch_task_running = False