application scoped objects

1 view
Skip to first unread message

qwcode

unread,
Jun 24, 2009, 12:48:53 AM6/24/09
to cherrypy-users
In the java servlet container world, you have the ServletContext hash
that provides a place to put "application scope" objects.

Is there such a thing in CherryPy? Is it the "Application" object?

Handler classes (including the root) are instantiated per Request,
correct?

Paweł Stradomski

unread,
Jun 24, 2009, 12:28:13 PM6/24/09
to cherryp...@googlegroups.com
W liście qwcode z dnia środa 24 czerwca 2009:

If you are using the default dispatcher then not, why would they? You pass an
instance to mount(), not class, so it would not even be possible to
instantiate them per-request.


--
Paweł Stradomski

Lakin Wecker

unread,
Jun 24, 2009, 12:33:04 PM6/24/09
to cherryp...@googlegroups.com
Pawel,

You're right, it doesn't instantiate them per request.

However, it might be possible via the __class__ attribute:
>>> class Foo(object):
... pass
...
>>> x = Foo()
>>> y = x.__class__()
>>> y
<__main__.Foo object at 0x9df7b0c>
>>> x
<__main__.Foo object at 0x9df7acc>

qwcode,

What do you plan to store at that level?

Lakin

Paweł Stradomski

unread,
Jun 24, 2009, 12:59:53 PM6/24/09
to cherryp...@googlegroups.com
W liście Lakin Wecker z dnia środa 24 czerwca 2009:

> Pawel,
>
> You're right, it doesn't instantiate them per request.
>
> However, it might be possible via the __class__ attribute:

Right, haven't thought of that. Though I don't think any sane framework would
do it.
--
Paweł Stradomski

fumanchu

unread,
Jun 24, 2009, 1:56:26 PM6/24/09
to cherrypy-users
On Jun 23, 9:48 pm, qwcode <qwc...@gmail.com> wrote:
> In the java servlet container world, you have the ServletContext hash
> that provides a place to put "application scope" objects.
>
> Is there such a thing in CherryPy?  Is it the "Application" object?

Yes.

Feel free to help me build http://tools.cherrypy.org/wiki/FromJava as
you learn more. :)


Robert Brewer
fuma...@aminus.org

qwcode

unread,
Jun 24, 2009, 4:18:26 PM6/24/09
to cherrypy-users
Thanks for all the replies, a few followups

1) ok, so the Application object is an equivalent of the
ServletContext in Java. According to the docs, all cherrypy apps are
wsgi apps, so does that mean all wsgi apps have an "application
scope"? For example, I've struggled to find a ServletContext parallel
in django, and no replies on their user list. Two examples of wanting
to have an application scoped object:
a) a compiled xslt template object (that's threadsafe) that will
be used repeatedly
b) a pylucene SearchIndexer object (that's threadsafe) that will
be used repeatedly

2) ok, handler *objects* are what are mounted (not classes), so that
answers my 2nd question.. so you have to be sure any members used in
support of the methods in your handler classes are thread-safe

Thanks
Reply all
Reply to author
Forward
0 new messages