List Info

Thread: application level data sharing




application level data sharing
user name
2006-11-21 18:05:48
Dyno Fu wrote:
>   what i wantta do is to share some data in memory
which is shared
> between each session. or in other words it's scope is 
> application level
> rather than session level.
> 
> class Root:
>          def __init__(self):
>                #where to put this data to share between
each
> session/request?
>                #something like
cherrypy.appContex.put("data",
> self.data)
>                self.data = "somedata" #may be
a large list or dict
> 
>                self.plot = Plot()
>                self.plot.expose = True
>          ...
> class Plot:
>         def __init__(self):
>         #how to get the data from application context?
>               self.data =  ? #something like
> cherrypy.appContext.get("data")
>          ...
> 
> i know, i can init the data and pass around with
parameter, for e.g.
>         self.plot = Plot(data)
> 
> i am here to seek a more elegance way in cherrypy, as
what we can do
> with Java Servlet -- there is a Web Context called
> "javax.servlet.ServletContext" scope, and we
can simply store and
> retrieve the data in application level. any suggestion?

I don't see how
javax.servlet.ServletContext.put("data", foo) is
"more
elegant" than self.data = foo <wink>. But it's
much easier in CP--stick
attributes into cherrypy.root (in CherryPy 2.x; use
cherrypy.request.app
in CherryPy 3). I wouldn't even bother adding such items to
each object;
just refer to cherrypy.root throughout your code:

class Root:
    def __init__(self):
        ...

class Plot:
    def handler(self, arg):
        if arg:
            root.data = arg
        return root.data


root = Root()
cherrypy.tree.mount(root)
root.data = "somedata"

Similarly, if you wanted some data to be request-scoped,
stick it into
the cherrypy.request object. Engine-scoped, stick it into
cherrypy.engine.


Robert Brewer
System Architect
Amor Ministries
fumanchuamor.org

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users?hl=en

-~----------~----~----~----~------~----~------~--~---

application level data sharing
user name
2006-11-22 01:32:45
Robert,

many thanx,
cherrypy.request.app that should be what i want. i am just
to find the
place to store data of application-scope available.

rgds,
Dyno


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users?hl=en

-~----------~----~----~----~------~----~------~--~---

application level data sharing
user name
2006-11-22 03:13:22
class Root():
...

app = cherrypy.tree.mount(Root(), config = config)
app.xxx = "some data"

in other places, xxx can be retrieved by

    cherrypy.reqeust.app.xxx

On Nov 22, 9:32 am, "Dyno Fu" <dyno...gmail.com> wrote:
> Robert,
>
> many thanx,
> cherrypy.request.app that should be what i want. i am
just to find the
> place to store data of application-scope available.
> 
> rgds,
> Dyno


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users?hl=en

-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )