Am 23.01.2006 um 23:24 schrieb Justin Johnson:
I've got some start up code that drops tables, creates them and
populates with some test data. I needed a place to initiate this
so I've put it into my model.py source file and used something akin
to a singleton pattern to make sure it just happens once.
What I'm seeing is that most of the time the code is actually
running twice. You can see it by just putting a 'print' inside
model.py and starting up.
Any explanation for this?
this could be cherrypy's autoreloader. It starts a second instance of
the script in a new process, so all startup code is run in both
instances.
Alternatively, where's a good insertion point to put start up code
into the framework?
well, do you really want to reinitialize your database every times
when you restart your process?
If you want a bit more control, place it in a separate script, or add
a url handler to your controller that calls it. You don't even need a
link for this url on your pages, a bookmark in the browser will di.
ciao
Martina