From 4a1d0e5fb4d94ca657f85d0ec0f9011485c012a5 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 14 Nov 2010 00:19:51 -0500 Subject: hold a lock while we mutate the registry: it's not safe for more than one thread to mutate it at runtime --- pyramid/mako_templating.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py index 7e9ae236f..b63009e2c 100644 --- a/pyramid/mako_templating.py +++ b/pyramid/mako_templating.py @@ -1,4 +1,5 @@ import os +import threading from zope.interface import implements from zope.interface import Interface @@ -51,6 +52,8 @@ class PkgResourceTemplateLookup(TemplateLookup): return TemplateLookup.get_template(self, uri) +registry_lock = threading.Lock() + def renderer_factory(info): path = info.name registry = info.registry @@ -70,7 +73,12 @@ def renderer_factory(info): module_directory=module_directory, input_encoding=input_encoding, filesystem_checks=reload_templates) - registry.registerUtility(lookup, IMakoLookup) + registry_lock.acquire() + try: + registry.registerUtility(lookup, IMakoLookup) + finally: + registry_lock.release() + return MakoLookupTemplateRenderer(path, lookup) -- cgit v1.2.3