Comments (9)
Original Author: kgk, Original Timestamp: 2012-04-18 23:08:34.716000
Original Body: Thread-local variable such tg.request and tg.response are not
available to streaming return values in turbogears applications.
i.e. you cannot do
@expose()
def mystream():
yield "boo"
if tg.request.environ['a'] == 0:
yield "bah"
for x in range (1000):
yield "blah"
During application initialization the RegistrtyManager is created
to handle thread local variable i.e. tg.request and tg.response.
TurboGears2-2.1.5: configuration.py:954
app = RegistryManager(app)
Paste-1.7.5.1bisque1-py2.6.egg/paste/registry:367
The RegistryManager includes code to pop registry values after the stream
has completed. However you must ask for this behavior with
app = RegistryManager(app, streaming = True)
from tg2.
Original Author: amolsf, Original Timestamp: 2012-05-02 10:59:01.596000
Original Body: - milestone: 2.2.0 --> Undetermined
from tg2.
Original Author: amolsf, Original Timestamp: 2012-05-02 10:59:02.099000
Original Body: As it was not one of the targets for 2.2 I'm moving it back to undetermined milestone for evaluation.
We should probably deeply check the side effects of lazy Stacked objects management from Paste RegistryManager as the registry manager expectes the response to always be an iterable he can consume when enabling streaming mode. This might have the side effect of consuming one character at time when returning the html response slowing down the application depending on what the TGApp returns.
from tg2.
Original Author: krispk, Original Timestamp: 2012-05-02 18:37:17.594000
Original Body: Would this be as simple as checking the return type i.e. string or has
an iter attribute and processing in the correct way?
from tg2.
After some debugging, I found that even though you are returning a string in turbogears it
is placed into a list or tuple before it gets to paste.. The following patch of paste basically
passes strings (templates) unchanged, but allowed streaming apps to access registry variable
(after patching turbogears as mentioned above)
BTW it's impossible to post this bug/enhancement to paste.. their bug reporting site has been down
for months now. http://trac.pythonpaste.org/pythonpaste/report
Revision: 1504
Branch: default
Author: Kristian Kvilekval <[email protected]> 2012-05-08 14:07:36
Committer: Kristian Kvilekval <[email protected]> 2012-05-08 14:07:36
Tags: tip
Parent: 1503:8b76085af20c (allow token parameter to be a list or a preformed string)
Don't penalize streaming applications.. test response if streaming needed.
------------------------------ paste/registry.py ------------------------------
@@ -372,11 +372,18 @@
app_iter = None
reg = environ.setdefault('paste.registry', Registry())
reg.prepare()
- if self.streaming:
- return self.streaming_iter(reg, environ, start_response)
+ #if self.streaming:
+ # return self.streaming_iter(reg, environ, start_response)
try:
app_iter = self.application(environ, start_response)
+ #print "REG ", type(app_iter)
+ if isinstance(app_iter, (list, tuple)):
+ #print "DIRECT"
+ return app_iter
+ #print "STREAMING"
+ return self.streaming_iter(app_iter, reg, environ)
+
except Exception, e:
# Regardless of if the content is an iterable, generator, list
# or tuple, we clean-up right now. If its an iterable/generator
@@ -404,9 +411,9 @@
return app_iter
- def streaming_iter(self, reg, environ, start_response):
+ def streaming_iter(self, app_iter, reg, environ):
try:
- for item in self.application(environ, start_response):
+ for item in app_iter:
yield item
except Exception, e:
# Regardless of if the content is an iterable, generator, list
from tg2.
The first question that comes to mind is this: Can we do this without patching Paste? Having our own, locally modified, copy is something that I do not like, and would very much like to avoid doing. Add in that we're not the maintainers for Paste, and this can be difficult to get published.
Is there a way to modify TG to fix this?
from tg2.
a0769d5 75273b2 and 29540be fixed this issue, making possible to access tg.request, tg.response and so on during streamed responses.
from tg2.
Thanks for fixing this.
What version is this fixed in 2.3?
from tg2.
yes, it's in 2.3
from tg2.
Related Issues (20)
- Using Kajiki & Jinja simultaneously doesn't work HOT 2
- configuration error: no challengers - Documentation for TG2 REST API with Bearer Token Authentication? HOT 1
- vontri gher HOT 2
- In quickstart template /error/document crashes if accessed directly
- Message in ErrorController should not include html tags
- Hooks documentration version 2.4.0 HOT 2
- Issues with @cached(type='memory') and no Accept-Language header HOT 1
- Error: tg.i18n.LanguageError: No translation file found for domain HOT 2
- "TypeError: No object (name: context) has been registered for this thread" when use config.__getitem__ in tgschedule
- kajiki include/import DOCTYPE tag HOT 2
- Python 3: TypeError (no context) which was not present on Python 2 HOT 2
- TurboGears2 and pytest conflict HOT 3
- ErrorPageApplicationWrapper without TraceErrorsMiddleware will mute tracebacks
- Secure attribute for webflash cookie HOT 3
- SQLAlchemy version conflict with TG2.4.3 devtools/SQLAlchemy >=1.4 and zope-sqlalchemy 1.4
- turbogears.org website certificate is expired HOT 1
- Activating Genshi lenient mode in Tg2
- localedir is overrides and not working
- Route/HTTP middleware after method should execute after exception response generate
- Error with objectproxy globals and current versions of mock
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tg2.