Reputation: 552
I have pserve --reload working with any python changes, but I still have to manually reload when I change a template.
I made this little script that monitors my templates folder for any changes, but what is the command to reload pserve? If I need to call a pserve method from within my Pyramids project, like in init.py or something, what is the method I would call to reload pserve?
#!/usr/bin/env python
import sys
import pyinotify
from subprocess import call
import time
wm = pyinotify.WatchManager()
mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_MODIFY
class EventHandler(pyinotify.ProcessEvent):
def process_IN_MODIFY(self, event):
print "Modified: ", event.pathname
# This is where my reload call would go...
# call(["pserve", "reload"])
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch("/path/to/my/pyramid/templates/", mask, rec=True, auto_add=True)
notifier.loop()
Upvotes: 2
Views: 2099
Reputation: 1158
Make sure you set your config object to take in the settings from the development.ini as well. Something like config = Configurator(settings = settings)
Upvotes: 1
Reputation: 15105
Pyramid already provides a method to reload templates without restarting pserve
by putting such configuration in a PasteDeploy development.ini
file or using environment variables. See Environment Variables and .ini File Settings. Of course, do not enable template reloading in production as it slows down your application.
Upvotes: 6
Reputation: 3329
By the way - nice workaround script. Steve is right, pyramid offers that out-of-the-box. But pyramid built-in watchdog behaviour depends also on your configuration. Including pyramid_jinja2 into your pyramid project triggers a lot of stuff in pyramid and makes some assumptions about template file extensions (*.jinja2) as well.
pyramid_jinja offers configuration for template reloading - it can be enabled/disabled as well. Since pyramid 1.5 (do you use it?) you can use setting `pyramid.reload_templates' as well.
But the best thing you can do is to try the pyramid scaffold that uses jinja2 templates. Takes you 5 minutes to setup, then you change a jinja2 template and see if pyramid is reloading or not. If pyramid is reloading, what I expect, you can continue to debug the problem with your current application.
Upvotes: 1