It seems that you are resetting the q object (because controller code
executes on each request)
It could be solved storing the object in session.

session.q = ...

(session supports only pickleable objects)

On 4 dic, 07:40, Martin Weissenboeck <mweis...@gmail.com> wrote:
> Hi Alan,
>
> I have tried to decorate two functions. But it notwork as I expected.
> Name of the application: queuetest, controller: default.py:
>
> from Queue import *
>
> @service.run
> def pp():  # Producer
>     q.put(request.now.isoformat())
>     return dict(size=q.qsize())
>
> @service.run
> def cc():  # Consumer
>     s = q.get()
>     return dict(time=s, size=q.qsize())
>
> @service.run
> def pc():  # call producer two times, consumer once
>     return [pp(), pp(), cc()]
>
> And in db.py:
>
> from Queue import *
> q=Queue()
>
> A call ofhttp://127.0.0.1:8000/queuetest/default/call/run/pcreturns:
> [{'size': 1}, {'size': 2}, {'size': 1, 'time':
> '2011-12-04T13:30:33.283000'}]
> That's ok.
>
> But I think the next call creates a NEW queue, starting with size 1
> [{'size': 1}, {'size': 2}, {'size': 1, 'time':
> '2011-12-04T13:33:45.126000'}]
>
> What shall I do to have ONE queue?
> Regards, martin
>
> 2011/12/2 Alan Etkin <spame...@gmail.com>
>
> > Depending on the type of data maybe you could use web2py services
> > interface.
>
> > First you define the set/get actions in some of the apps and decorate
> > them as services. Then from any application you can consume this
> > services for data transactions.
>
> > The web2py book covers services and RPC in 9th chapter
>
> > Apps can share session objects too and you could store a sequence on a
> > common session:
> > (web2py chapter 4)
> > "...One app can load the session of another app using the command:
> > 1
> > session.connect(request, response, masterapp='appname', db=db)
>
> > Here "appname" is the name of the master application, the one that
> > sets the
> > initial session_id in the cookie. db is a database connection to the
> > database
> > that contains the session table (web2py_session). All apps that share
> > sessions
> > must use the same database for session storage. "
>
> > On Dec 1, 6:06 pm, Martin Weissenboeck <mweis...@gmail.com> wrote:
> > > Hi,
>
> > > I want to use one and only one queue (q).
>
> > > Some applications/controllers should act as producers (q.put(item)) and
> > > some applications/controllers as consumers (item=q.get()), but with only
> > > one queue.
>
> > > How can this be done?
>
> > > Regards, Martin
>
>

Reply via email to