I was looking into refactoring the auto-reloading code and I wanted to 
gather some feedback. There is some potential to squash several bugs in one 
go[1][2][3].

To begin with we can get rid of the Jython specific code, Jython is 2.7 
only at the moment and I don't think that will change soon.

We currently have an implicit dependency on `pyinotify`, if it's installed 
a more efficient inotify-based watcher is used. I've never seen this 
advertised anywhere, and pyinotify has not received any updates in over 3 
years. There is also this[4] blog post which says perhaps pyinotify isn't 
the best. I think the best way forward is to use the 'watchdog' package if 
it's installed, as it contains platform-specific implementations for 
observing file modifications[6] and even their fallback polling observer[7] 
is better than any we could include in Django. If we want to add the 
ability to use the watchman service with Django (something I fully agree 
with) perhaps adding support for it directly to that library would be more 
preferable than bundling it in Django itself.

The current autoreloading code contains some translations specific code 
that would be good to split out. It would be nice to have the autoreload 
module be as focused as possible on just detecting and handling file 
changes in a pretty neutral way, other parts of Django could register 
subscriptions to be notified when files change and can handle it themselves 
(perhaps via signals?). For example the cached template loader could 
register a callback to fire whenever one if it's source files changes and 
delete that entry from the cache, the translations framework could handle 
.mo files changing itself or third party modules can use these hooks to do 
whatever crazy things they want.

I've got a first-draft branch with a cleanup of the autoreload code 
here[8], any feedback would be welcome. It currently doesn't handle syntax 
error reloading or the i18n resetting. Could the syntax error reloading be 
improved with a clean re-implementation of the autoreloader? I can't think 
of any nice ways to handle it.

1. https://code.djangoproject.com/ticket/27685#ticket
2. https://code.djangoproject.com/ticket/25624
3. https://code.djangoproject.com/ticket/25791
4. 
http://www.serpentine.com/blog/2008/01/04/why-you-should-not-use-pyinotify/
5. 
https://pythonhosted.org/watchdog/_modules/watchdog/observers/polling.html
6. https://pythonhosted.org/watchdog/api.html#module-watchdog.observers
7. 
https://pythonhosted.org/watchdog/_modules/watchdog/observers/polling.html
8. 
https://github.com/orf/django/blob/27685-autoreloader-refactor/django/utils/autoreload.py

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/b33d73e3-6ff5-431d-b9ff-7db1219d11cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to