Alexandre Bourget

geek joy

Using memento with Pylons

January 20, 2010 at 04:57 PM

Tired of using paster serve --reload development.ini and waiting for your code to reload ?

memento allows you to dynamically reload your code -- without restarting your whole server -- or parts of your code.

Install it:

$ easy_install memento

To integrate with Pylons, follow these steps:

Go to your config/, and add:

import memento

Then, a bit lower, replace:

def make_app(...):
    # The Pylons WSGI app
    app = PylonsApp()


def make_app(...):
    # The Pylons WSGI app
    #app = PylonsApp()
    app = memento.Assassin('pylons.wsgiapp:PylonsApp()', ['yourpackage'])

The second parameter to Assassin() is a list of packages you want reloaded on each request. You probably want your whole package to be reloaded, or you can be more granular.

NOTE: don't forget the () after the PylonsApp, because it has to call the object to get a WSGI app. You'll get errors otherwise

The neat thing is I think you can disable that in real-time also, by changing the value of app.mode ('on' = 'on and 'off' = 'off, as you've guessed), so I guess you'd like to keep a copy of that 'app' before you lose it's reference lower in

blog comments powered by Disqus