On Tue, Apr 19, 2011 at 1:14 AM, Diez B. Roggisch <[email protected]> wrote:
>
> The problem is that you modify the Decoration. But that can lead to 
> race-conditions in multi-threaded environments.
>
> There is a thread-safe implementation that I fixed, which is called 
> "override_template". It's inside the decorators package. If you'd manage to 
> make the implementation based on that, it should be ok. If not as such, take 
> a look, and implement your approach accordingly.

Thank you Diez for pointing that out,
actually I wrote the code in about 1 hour before going to sleep and I
went to sleep with the strange feeling that it might have that problem
due to use_custom_format saving the format inside the controller
itself, but didn't have time/wanted to check it as I was tired :D

Also use_custom_format, due to the fact that it changes the decorated
function, switches the template permanently, which is not what I
suppose it should be expected to do.
I think that changing it to save the wanted custom format inside the
request instead of saving it inside the decorated function would be
preferred and solve both the issues.
Documentation suggests to call use_custom_format to switch between
custom formats, but doing that has indeed a set of problems from
switching the template forever to causing race conditions.

As you suggested I'm going to reimplement right now the expose_mobile
decorator by using override_template which avoids those problems due
to the fact that it actually saves the overridden template inside the
request itself. I didn't use it at the first time as custom_formats
are more comfortable as you register a short name to switch between
them.

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to