You can do something like

class Queue:
    forever = 10**10
    def __init__(self):
        import thread
        self.q=[]
        self.lock=thread.allocate_lock()
    def enque(self,o):
        self.lock.acquire()
        self.q.append(o)
        self.lock.release()
    def dequeue(self):
        self.lock.acquire()
        o = self.q[0]
        del q[0]
        self.lock.release()
        return o
    def __len__(self):
        self.lock.acquire()
        ell=len(self.q)
        self.lock.release()
        return ell

queue=cache.ram('queue',lambda:Queue,Queue.forever)
queue.enqueue('object')
print len(queue)
o = queue.dequeue()

If you define it in a model it will be visible everywhere, including
cron scripts. I am not sure if the lock is really necessary (because
of the global interpreter lock) but it is safe.

queue.append(


On Jul 9, 4:07 pm, kralin <andrea.pierle...@gmail.com> wrote:
> Hi All,
> I'm diving into web2py that at the moment gives me the power and the
> time do a lot of cool things. so thanks a lot to you guys.
> I was wondering if any of you ever had the need to set a queue for a
> heavy process.
> Let's suppose I've got one heavy process that takes 2 mins to run on a
> singol-processor machine.
> now if 10 user submit the process at (more or less) the same time, is
> there a way to schedule the process based on the first coming, first
> to have response rule? each of this user should be able to see their
> result once completed or see something like"wait, 8 jobs still in
> queue"
>
> I know it can be done easily with external job sheduler, but it will
> require to use a separate process, not beeing portable, and a little
> bit more headhache...
>
> a quick and dirty solution wuld be to run a cron each, let's say, 2
> mins and if a process is queue, execute it, but I feel that can be
> done in a much more elegant way.
>
> what do youthink?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to