[Tutor] threading.currentThread() always same across request ?

Arun Kumar PG arunkumarpg at gmail.com
Sat Apr 14 08:13:02 CEST 2007


Guys,

I have a web application and I want to store an object per request so thta
that is available across all classes till end of request.

I am planning  to write the below code in my entry program which is executed
as soon as a request comes:

entry.py
  import threading

  th = threading.currentThread()
  th.service = somemod.Service()

then in other parts of program whereever I want to use service:

  th = threading.currentThread()
  if hasattr(th, 'service'):
    th.service.call_whatever()

I am wondering if I will ever face a problem in this case ? I want to make
sure that since the request till the end the same "service" object is
available and it should not collide with any other request. Since it's a web
application multilple request may come simutaneously.

Is this approach correct ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070414/c5900456/attachment-0001.html 


More information about the Tutor mailing list