Reload handler #14

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

galvez commented Nov 13, 2010

This is intended to be a unobtrusive addition to werkzeug.serving.run_simple() which adds a reload_handler parameter. This parameter can be used to specify a function that should be called whenever a file watched by the reloader changes. The changed file's full path is passed to the function as the first and only argument.

My personal motivation is to integrate werkzeug's reloader with other compiling tools, such as a CSS compiler I'm currently working on. But I can imagine it to be useful in a wide range of scenarios.

Jonas Galvez Adds a reload_handler parameter, which can be used to specify a funct…
…ion that should be called whenever a file watched by the reloader changes. The changed file's full path is passed to the function as the first and only argument.
ea273a1
galvez commented Nov 13, 2010

Further insight into how I'm using this:

def web():
  import myapp
  from support import find_hcss_files, recompile_hcss_file
  myapp.app.run(
    host='0.0.0.0', port=80, debug=True, 
    extra_files=find_hcss_files(), reload_handler=recompile_hcss_file
  )
Owner

Nice idea, but before I pull that I have to check if I like the interface.

galvez commented Nov 20, 2010

Sure, in fact I expected you to want to mull over the API for this. Honestly I'll be glad with anything that works. Just would love to see it in the next dot release so I can release flask-hcss :)

@robsonpeixoto robsonpeixoto commented on the diff Dec 31, 2013
werkzeug/serving.py
@@ -380,7 +380,7 @@ def make_server(host, port, app=None, threaded=False, processes=1,
passthrough_errors, ssl_context)
-def reloader_loop(extra_files=None, interval=1):
+def reloader_loop(extra_files=None, interval=1, reload_handler=None):
robsonpeixoto
robsonpeixoto Dec 31, 2013

IHMO, should be reload_callbacks

Owner

From what i can see this is the same as #220. As i said there, you can just run code before calling run_simple, which is probably good enough:

def web():
    import myapp
    from support import find_hcss_files, recompile_hcss_file
    recompile_hcss_file()
    myapp.app.run(
        host='0.0.0.0', port=80, debug=True, 
        extra_files=find_hcss_files()
    )
@untitaker untitaker closed this Aug 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment