Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Early session initialization problems
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Voltron  
View profile  
 More options Jun 26, 2:47 am
From: Voltron <nhy...@googlemail.com>
Date: Thu, 25 Jun 2009 23:47:21 -0700 (PDT)
Local: Fri, Jun 26 2009 2:47 am
Subject: Early session initialization problems
I need to have my session initialized very early so that I can pass
them to the global environment of the templating system I am using. I
read somewhere about these solutions:

storage_class = storage_type.title() + 'Session'
storage_class = globals()[storage_class]
if not hasattr(cherrypy, "session"):
    if hasattr(storage_class, "setup"):
        storage_class.setup(**kwargs)

My questions are:

1. Some backends do not have the "setup()" function, how should these
be handled then?
2. If the backend is initialized also by turning "tools.sessions.on"
in the global configuration, and separately again when triggering an
early initialization, would that lead to problems? Asynchronous
sessions?

Thanks


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
fumanchu  
View profile  
 More options Jun 27, 3:06 pm
From: fumanchu <fuman...@aminus.org>
Date: Sat, 27 Jun 2009 12:06:36 -0700 (PDT)
Local: Sat, Jun 27 2009 3:06 pm
Subject: Re: Early session initialization problems
On Jun 25, 11:47 pm, Voltron <nhy...@googlemail.com> wrote:

> I need to have my session initialized very early so that I can pass
> them to the global environment of the templating system I am using. I
> read somewhere about these solutions:

How early is early? Sessions are currently initialized at the
'before_request_body' hook. See the diagram at http://www.cherrypy.org/wiki/RequestObject.

If your templating system runs at the 'on_start_resource' hook, the
best approach would be to either move it to the 'before_request_body'
hook (at, say, priority 60 so it runs after the session tool), or move
the session tool to run at the 'on_start_resource' hook, with a low
priority number so it runs before your templating setup.

> storage_class = storage_type.title() + 'Session'
> storage_class = globals()[storage_class]
> if not hasattr(cherrypy, "session"):
>     if hasattr(storage_class, "setup"):
>         storage_class.setup(**kwargs)

> My questions are:

> 1. Some backends do not have the "setup()" function, how should these
> be handled then?

That's what the 'hasattr' check is for. Nothing needs to be done if a
backend has no such method.

> 2. If the backend is initialized also by turning "tools.sessions.on"
> in the global configuration, and separately again when triggering an
> early initialization, would that lead to problems? Asynchronous
> sessions?

The code you pasted above is from cherrypy.lib.sessions.init(), which
is called when you turn tools.sessions.on. If you're duplicating the
functionality of init() somewhere else, you probably don't want init()
to run again. So you'd usually turn the tool off and manually add the
hooks it does. Fortunately, *if* you duplicate *all* of sessions.init,
you'll see there's a guard in there against running twice, so in the
case of the session tool you can work around this. But don't do that;
instead, use the priority system to run your tools in the desired
order.

Robert Brewer
fuman...@aminus.org


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Voltron  
View profile  
 More options Jun 30, 4:56 am
From: Voltron <nhy...@googlemail.com>
Date: Tue, 30 Jun 2009 01:56:23 -0700 (PDT)
Local: Tues, Jun 30 2009 4:56 am
Subject: Re: Early session initialization problems
Thanks! I will take a look again at the priority system

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google