Ok Michael,

thanks for confirming there's something wrong and simply I did not
misunderstood.

The problem is that, in a single thread, `request.user` *survives from
request to request* and is not affected by changes (like items deletion)
occurring in other threads until a `DBSession.refresh(request.user)` is
issued in that thread.

Here is my code:

#my session
DBSession = scoped_session(
    sessionmaker(extension=ZopeTransactionExtension()))

#my request class
class RequestWithUserAttribute(Request):
    @reify
    def user(self):
        userid = unauthenticated_userid(self)
        if userid is None:
            return None
        else:
            return DBSession.query(User) \
                .filter(User.userid==userid) \
                .first()

#set my custom request which provide user property
def main(global_config, **settings):
    ...
    config.set_request_factory(RequestWithUserAttribute)

============

My [apache modwsgi setup][1] where 4 threads are set.
Reducing to 1 thread (obviously) the problem disappears.

<VirtualHost *:80>
    ...
    # Setup mod_wsgi
    # Use only 1 Python sub-interpreter.  Multiple sub-interpreters
    # play badly with C extensions.
    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On
    WSGIDaemonProcess pyramid \
       user=your_username group=your_username \
       processes=1 \
       threads=4 \
       python-path=/home/your_username/bmh/env/lib/python2.6/site-packages
    WSGIScriptAlias / /home/your_username/bmh/env/pyramid.wsgi
    <Directory /home/your_username/bmh/env>
        WSGIProcessGroup pyramid
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

[1] http://docs.pylonsproject.org/projects/pyramid/1.0/tutorials/modwsgi/

I'll post any other code you may need.

Thanks for your attention
neurino



On Mon, Oct 17, 2011 at 11:11 PM, Michael Merickel <mmeri...@gmail.com>wrote:

> You would have to paste code to explain why your user object isn't
> re-queried between requests, because that makes no sense. All the @reify
> decorator does is cache the object "within a single request", it doesn't
> affect other threads or other requests at all. All I can think of is that
> you are either looking at the output wrong or you are sharing a database
> session across threads.
>
> --
>
> Michael
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to pylons-discuss@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discuss+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to