| 152 | |
| 153 | === Improved autoreloader (#27685) === |
| 154 | * '''Complexity:''' Medium |
| 155 | |
| 156 | Django's development server includes an auto-reloader. Its design is quite old. It keeps a list of imported Python files (as well as .mo files, there's a hardcoded special case), checks every second the mtime of these files, and triggers a reload if a file was updated. This cannot be good for battery life. |
| 157 | |
| 158 | A more efficient implementation based on inotify is available on Linux. An implementation based on kqueue was developed at some point but quickly removed because of kqueue limitations (#21621). |
| 159 | |
| 160 | Several open-source projects provide modern and robust building blocks for building the autoreload feature. The most mature in general is probably watchman. The most mature Python library is probably watchdog. However their APIs are quite low level and there's no trivial way to integrate them with Django's development server. |
| 161 | |
| 162 | The first goal of this project is to figure out and implement this integration. This means rebuilding the development server's autoreloading feature, perhaps with a slightly different behavior and hopefully with better performance, while preserving the main APIs (`runserver`, `runserver --no-reload`). |
| 163 | |
| 164 | It would make sense to switch from watching all imported Python files to watching the current directory. Modifying non-Python files whose content is somehow cached in the Python process happens and is regularly reported as a bug, while modifying files in `$VIRTUAL_ENV/lib/pythonX.Y/site-packages` is an uncommon case. |
| 165 | |
| 166 | It will be a good opportunity to fix various bugs of the autoreloader such as the inability to detect the addition of a file, typically an `admin.py`. |
| 167 | |
| 168 | The second goal is to improve configurability of the autoreloader, perhaps by exposing the underlying library's configuration knobs. This will allow people to customize the behavior according to their needs, for example if they want to go back to the previous behavior and watch `$VIRTUAL_ENV`. |