Key error when rendering under load

79 views
Skip to first unread message

Ksenia

unread,
Apr 20, 2009, 10:51:35 AM4/20/09
to Mako Templates for Python
Hi,

I am testing my home-made WSGI app with ab. To increase performance
I've added module_directory parameters and filesystem_checks to
TemplateLookup. It works great, the rendering is much faster, but with
module_directory parameter added, 1 or 2 of 100 requests fail. On the
debug page I can see a traceback:
(copy-paste from Weberror page)
[...]
Module page_html:24 in _mako_inherit view
>> return runtime._inherit_from(context, 'master.html', _template_uri)
Module mako.runtime:297 in _inherit_from view
>> template = _lookup_template(context, uri, calling_uri)
Module mako.runtime:322 in _lookup_template view
>> return lookup.get_template(uri)
Module mako.lookup:85 in get_template view
>> return self.__load(srcfile, uri)
Module mako.lookup:127 in __load view
>> self.__collection[uri] = Template(uri=uri, filename=posixpath.normpath(filename), lookup=self, module_filename=(self.modulename_callable is not None and self.modulename_callable(filename, uri) or None), **self.template_args)
Module mako.template:84 in __init__ view
>> del sys.modules[self.module_id]
KeyError: 'master_html'

Is this something in environment that brings Mako down? I can imagine
that my home-grown WSGI app / framework is not as reliable as some
well-tested frameworks. Or is this due to some OS limitations? (OSX
10.5)

Thanks
Ksenia

Michael Bayer

unread,
Apr 20, 2009, 11:08:08 AM4/20/09
to mako-d...@googlegroups.com

that error suggests that multiple Template objects of the same path are
loading into memory at the same time, which shouldn't be possible because
the __load() method of TemplateLookup is mutexed. So would need to know
what "I've added module_directory parameters and filesystem_checks to
TemplateLookup" means - if you modified your TL, then yeah it looks like
you've broken its thread-safety.

Ksenia

unread,
Apr 20, 2009, 2:34:12 PM4/20/09
to Mako Templates for Python
Michael, thank you for a quick answer! After checking the code twice
I've found the problem - the global instance of TemplateLookup was by
mistake instantiated on every request instead of only once during
application startup. After fixing it everything works as expected.

Ksenia
Reply all
Reply to author
Forward
0 new messages