summaryrefslogtreecommitdiff
path: root/docs/designdefense.rst
diff options
context:
space:
mode:
authorSteve Piercy <web@stevepiercy.com>2016-02-12 20:06:27 -0800
committerSteve Piercy <web@stevepiercy.com>2016-02-12 20:06:27 -0800
commit288b462aa21ac0d9086fc2a616033468dc3846a6 (patch)
tree1e3e33621019c332605559e06bfb5fdcf5fd978c /docs/designdefense.rst
parent63f060a64926de402a06dc06805735cba4ba02b0 (diff)
downloadpyramid-288b462aa21ac0d9086fc2a616033468dc3846a6.tar.gz
pyramid-288b462aa21ac0d9086fc2a616033468dc3846a6.tar.bz2
pyramid-288b462aa21ac0d9086fc2a616033468dc3846a6.zip
minor grammar and punctuation through "thread locals are a nuisance"
Diffstat (limited to 'docs/designdefense.rst')
-rw-r--r--docs/designdefense.rst45
1 files changed, 24 insertions, 21 deletions
diff --git a/docs/designdefense.rst b/docs/designdefense.rst
index 530a9c17c..98005f3f9 100644
--- a/docs/designdefense.rst
+++ b/docs/designdefense.rst
@@ -1405,7 +1405,9 @@ great fit for very large applications and applications that need to be
arbitrarily extensible.
-"Stacked Object Proxies" Are Too Clever / Thread Locals Are A Nuisance
+.. _thread_local_nuisance:
+
+"Stacked object proxies" are too clever / thread locals are a nuisance
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Some microframeworks use the ``import`` statement to get a handle to an
@@ -1448,32 +1450,33 @@ code below:
for i in range(10):
print(i)
-By its nature, the *request* object created as the result of a WSGI server's
-call into a long-lived web framework cannot be global, because the lifetime
-of a single request will be much shorter than the lifetime of the process
-running the framework. A request object created by a web framework actually
-has more similarity to the ``i`` loop counter in our example above than it
-has to any comparable importable object defined in the Python standard
+By its nature, the *request* object that is created as the result of a WSGI
+server's call into a long-lived web framework cannot be global, because the
+lifetime of a single request will be much shorter than the lifetime of the
+process running the framework. A request object created by a web framework
+actually has more similarity to the ``i`` loop counter in our example above
+than it has to any comparable importable object defined in the Python standard
library or in normal library code.
However, systems which use stacked object proxies promote locally scoped
-objects such as ``request`` out to module scope, for the purpose of being
+objects, such as ``request``, out to module scope, for the purpose of being
able to offer users a nice spelling involving ``import``. They, for what I
-consider dubious reasons, would rather present to their users the canonical
-way of getting at a ``request`` as ``from framework import request`` instead
-of a saner ``from myframework.threadlocals import get_request; request =
-get_request()`` even though the latter is more explicit.
+consider dubious reasons, would rather present to their users the canonical way
+of getting at a ``request`` as ``from framework import request`` instead of a
+saner ``from myframework.threadlocals import get_request; request =
+get_request()``, even though the latter is more explicit.
It would be *most* explicit if the microframeworks did not use thread local
-variables at all. Pyramid view functions are passed a request object; many
-of Pyramid's APIs require that an explicit request object be passed to them.
-It is *possible* to retrieve the current Pyramid request as a threadlocal
-variable but it is a "in case of emergency, break glass" type of activity.
-This explicitness makes Pyramid view functions more easily unit testable, as
-you don't need to rely on the framework to manufacture suitable "dummy"
-request (and other similarly-scoped) objects during test setup. It also
-makes them more likely to work on arbitrary systems, such as async servers
-that do no monkeypatching.
+variables at all. Pyramid view functions are passed a request object. Many of
+Pyramid's APIs require that an explicit request object be passed to them. It is
+*possible* to retrieve the current Pyramid request as a threadlocal variable,
+but it is an "in case of emergency, break glass" type of activity. This
+explicitness makes Pyramid view functions more easily unit testable, as you
+don't need to rely on the framework to manufacture suitable "dummy" request
+(and other similarly-scoped) objects during test setup. It also makes them
+more likely to work on arbitrary systems, such as async servers, that do no
+monkeypatching.
+
Explicitly WSGI
+++++++++++++++