diff options
author | Ryan Petrello <lists@ryanpetrello.com> | 2014-03-18 10:37:33 -0700 |
---|---|---|
committer | Ryan Petrello <lists@ryanpetrello.com> | 2014-03-19 08:04:14 -0700 |
commit | b79f90f7b248d6f66514d4d452fbc850d35045dd (patch) | |
tree | a42b83205c90386e369b7d851cf9d1190f79c9f9 /pecan | |
parent | c047087b72d37f094320e3bdff3fc24a79551ea8 (diff) | |
download | pecan-b79f90f7b248d6f66514d4d452fbc850d35045dd.tar.gz |
Delay the `threading.local` import to allow for eventlet/gevent monkeypatching.
Fixes bug 1294177
Change-Id: I51482148602d85e40230547d0e19cf0c2a0c6d8a
Diffstat (limited to 'pecan')
-rw-r--r-- | pecan/core.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/pecan/core.py b/pecan/core.py index b9c88a1..1e4e7f3 100644 --- a/pecan/core.py +++ b/pecan/core.py @@ -2,7 +2,6 @@ try: from simplejson import loads except ImportError: # pragma: no cover from json import loads # noqa -from threading import local from itertools import chain from mimetypes import guess_type, add_type from os.path import splitext @@ -24,7 +23,7 @@ from .middleware.recursive import ForwardRequestException # make sure that json is defined in mimetypes add_type('application/json', '.json', True) -state = local() +state = None logger = logging.getLogger(__name__) @@ -200,7 +199,10 @@ class Pecan(object): def __init__(self, root, default_renderer='mako', template_path='templates', hooks=lambda: [], custom_renderers={}, extra_template_vars={}, - force_canonical=True, guess_content_type_from_ext=True, **kw): + force_canonical=True, guess_content_type_from_ext=True, + context_local_factory=None, **kw): + + self.init_context_local(context_local_factory) if isinstance(root, six.string_types): root = self.__translate_root__(root) @@ -221,6 +223,12 @@ class Pecan(object): self.force_canonical = force_canonical self.guess_content_type_from_ext = guess_content_type_from_ext + def init_context_local(self, local_factory): + global state + if local_factory is None: + from threading import local as local_factory + state = local_factory() + def __translate_root__(self, item): ''' Creates a root controller instance from a string root, e.g., |