you should attach the global variable to a module,e.g. web

2009/4/1, Merlin <[email protected]>:
>
> I don't want to store the data in the database, but to use the server
> memory instead. For example, I would like to have a global Queue, http
> requests will populate it and a separate thread will consume the
> contents. Here is a small example:
>
> import web
> import threading
> import Queue
>
> urls = ('/([0-9]*)', 'index')
>
> q = Queue.Queue()
>
> class index:
>   def GET(self, number):
>     q.put(number)
>     return 'you pushed ' + number
>
> if __name__ == '__main__':
>   print globals()
>   app = web.application(urls, globals())
>   http = threading.Thread(target = app.run)
>   http.start()
>   while True:
>     number = q.get()
>     print number
>     if number == 13:
>       break
>
> Unfortunately, as I found out the global q variable is recreated for
> each request. Obviously, this is not what I want. Is there a way to
> use the real global variables within requests?
>
> Thanks in advance
> >
>

-- 
从我的移动设备发送

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to