#27685: Allow autoreloader to use watchman
--------------------------------------+------------------------------------
     Reporter:  Aymeric Augustin      |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Utilities             |                  Version:  master
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  1                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by Tom):

 Hey Aymeric, thanks for the response!

 1. I believe so. Currently I'm envisioning the watchdog backend first, as
 it seems pretty easy to add. That supports watching individual directories
 without a glob, so we'd need to do some manual work to find out if any
 file changes match out glob expressions (which doesn't sound too
 difficult?). Services like watchman take a directory and a glob pattern so
 it does that for us. I can't think of any other more generic method than a
 (direcrtory, glob) tuple?

 2. When the autoreloader is ready to watch for events a
 `autoreload_started` signal is fired, with the autoreloader instance as
 it's sender. It knows when to send this signal by waiting for `apps.ready`
 in a while loop, which is a bit iffy IMO. Any handlers (like the one in
 `i18n`) are triggered and can use `sender.watch(...)` to subscribe to
 anything they want - in i18n's case it's .mo files in various places.
 When any file is changed a `file_changed` signal is sent with the path,
 and each handler can do whatever it pleases with that path. If any handler
 returns True then the server will not restart due to this change. I like
 this approach because it's just simple signals, and you don't care about
 any settings while registering them. If the debug server is not used (or
 autoreload is turned off) then no signals will be sent. Simple!

 3. I believe the `autoreload` module is private, but there are a few
 usages on GitHub:
 
https://github.com/search?l=Python&q=django.utils.autoreload&type=Code&utf8=%E2%9C%93

 A lot of these are similar to these:

 
https://github.com/JamesTing/ConnectNodes/blob/ba4f6a82416a81d31e51c00d5472ee48098388d8/
 后台/reload.py
 https://github.com/ch3ll0v3k/Doc-
 
Browser/blob/ea31f3c3ce82621f77311bcf536455cb16f137a3/pyinstaller/build/lib.linux-i686-2.7/PyInstaller/loader/rthooks/pyi_rth_django.py
 
https://github.com/tyru/homedir/blob/98166ffee204db6083bed644d6cb438d274e2635/bin.d/google_appengine/google/appengine/_internal/django/core/management/commands/runserver.py#L82

 So to keep some semblance of compatibility we should:
 Implement a `code_changed` function that just runs the current
 implementation (for people using uwsgi in development?)
 Add a restart_with_reloader method (seems to be for pyinstaller compat)
 Add a main() method.

 None of these seem insurmountable IMO.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/27685#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.eb1bdd1ff3f38a408e99528097f7c357%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to