threadsafety in cherrypy with kid

I

infidel

I have just recently discovered CherryPy and Kid (many kudos to the
respective developers!) and am tinkering with them to see what I can
come up with.

The application I eventually want to write will eventually require the
python code to call stored procedures in a database which means I'll
need to run CherryPy with a threadPool so individual database calls
don't block the whole server.

I'm not to that point yet, I'm just getting a feel for what is
possible, and I wanted to make sure the following usage of my Kid
template (named "index") is threadsafe:


from cherrypy import cpg
import kid; kid.enable_import()
from infidel.web import index

class Root(object):

@cpg.expose
def index(self, *args, **kwargs):
count = cpg.request.sessionMap.get('count', 0) + 1
cpg.request.sessionMap['count'] = count
template = index.Template(times=count)
return template.serialize(output='html-strict')


if __name__ == '__main__':
cpg.root = Root()
cpg.server.start(configFile = 'web.ini')


Does it matter that I've done the import of index at the module level
instead of inside the index method? The example at the CherryPy
recipes site does this:


from cherrypy import cpg
import kid

class HomePage:

def index(self):
test = kid.Template(file='test.kid')
test.title = "Test Kid Page"
test.lines = ['qwe','asd','zxc']
return test.serialize(output='xhtml')

index.exposed = True

if __name__ == "__main__":
cpg.root = HomePage()
cpg.server.start()


Is there a qualitative difference between what I've done and what the
examle does?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top