Search code examples
pythonpyramid

Additional files / directories to be monitored by Pyramid for autorestart


Pyramid has a nifty feature of restarting automatically if some .py or .ini file in its app scope have changed.

I have some more files (they're not .py nor .ini) that I need watched — how do I add them to Pyramid monitoring?


Solution

  • You (and may be some day pyramid itself) might be better of with implementing the desired behaviour into a custom watchdog implementation. Just follow my thoughts...

    Create a script that takes your PasteDeploy .ini file to run the pserve commands and installs a watchdog for the file extensions to monitor.

    Watchdog event handler just changes modification time of your .ini file since this file is already monitored by pyramid watcher.

    $ touch pyramid.ini
    

    results in a reload:

    pyramid.ini changed; reloading...
    -------------------- Restarting --------------------
    2015-04-29 08:51:05,216 INFO  [ZEO.ClientStorage] ('localhost', 8100) ClientStorage (pid=5263) created RW/normal for storage: '1'
    2015-04-29 08:51:05,217 INFO  [ZEO.cache] created temporary cache file '<fdopen>'
    2015-04-29 08:51:05,227 INFO  [ZEO.ClientStorage] ('localhost', 8100) Testing connection <ManagedClientConnection ('127.0.0.1', 8100)>
    2015-04-29 08:51:05,228 INFO  [ZEO.zrpc.Connection('C')] (127.0.0.1:8100) received handshake 'Z3101'
    2015-04-29 08:51:05,329 INFO  [ZEO.ClientStorage] ('localhost', 8100) Server authentication protocol None
    2015-04-29 08:51:05,331 INFO  [ZEO.ClientStorage] ('localhost', 8100) Connected to storage: ('localhost', 8100)
    2015-04-29 08:51:05,332 INFO  [ZEO.ClientStorage] ('localhost', 8100) No verification necessary -- empty cache
    Starting server in PID 5263.
    serving on http://0.0.0.0:6543
    

    You could even import useful stuff from pserve module that fits your use case. Look at this scripting approach to get an idea on how to drive a watchdog.