tornado.autoreload — Automatically detect code changes in development¶
Most applications should not access this module directly. Instead,pass the keyword argument to thetornado.web.Application
constructor (or debug=True
, whichenables this setting and several others). This will enable autoreloadmode as well as checking for changes to templates and staticresources. Note that restarting is a destructive operation and anyrequests in progress will be aborted when the process restarts. (Ifyou want to disable autoreload while using other debug-mode features,pass both debug=True
and autoreload=False
).
The command-line wrapper and Application debug modes can be used together.This combination is encouraged as the wrapper catches syntax errors andother import-time failures, while debug mode catches changes oncethe server has started.
Reloading loses any Python interpreter command-line arguments (e.g. -u
)because it re-executes Python using and sys.argv
.Additionally, modifying these variables will cause reloading to behaveincorrectly.
tornado.autoreload.
addreload_hook
(_fn)¶
Add a function to be called before reloading the process.
Note that for open file and socket handles it is generallypreferable to set theFDCLOEXEC
flag (using ortornado.platform.auto.set_close_exec
) insteadof using a reload hook to close them.
tornado.autoreload.
main
()[源代码]
Command-line wrapper to re-run a script whenever its source changes.
Scripts may be specified by filename or module name:
Running a script with this wrapper is similar to calling at the end of the script, but this wrappercan catch import-time problems like syntax errors that would otherwiseprevent the script from reaching its call to .
tornado.autoreload.
start
(_io_loop=None, check_time=500)[源代码]
Begins watching source files for changes.
在 4.1 版更改: Theioloop
argument is deprecated.
tornado.autoreload.
wait
()[源代码]
Wait for a watched file to change, then restart the process.
Intended to be used at the end of scripts like unit test runners,to run the tests again after any source file changes (but see alsothe command-line interface inmain
)
tornado.autoreload.
(_filename)¶
Add a file to the watch list.
All imported modules are watched by default.