To monitor file changes, you can use the cross-platform watchdog module, but it may not support Python 3.
The pyinotify module can be used on Linux platform.
A simple way is to check the mtime (last modification time) of the file every few seconds (Tornado uses this method), but it is more resource-intensive.
PS: These are different from git. git has its own database, which stores the previous version of the file. When you git status it will compare the file in the current workspace with the version it has saved.
You can refer to the debug mode of django or flask, which will automatically detect file changes and then restart the development server. However, I have not studied their implementation in detail. You can take a look at their source code
To monitor file changes, you can use the cross-platform watchdog module, but it may not support Python 3.
The pyinotify module can be used on Linux platform.
A simple way is to check the
mtime
(last modification time) of the file every few seconds (Tornado uses this method), but it is more resource-intensive.PS: These are different from git. git has its own database, which stores the previous version of the file. When you
git status
it will compare the file in the current workspace with the version it has saved.PPS: So your needs haven’t been made clear yet.
You can refer to the debug mode of django or flask, which will automatically detect file changes and then restart the development server. However, I have not studied their implementation in detail. You can take a look at their source code