i develop webapp to administrate a Kerbers, LDAP and AFS network. I was
able to create a custom Identity-Provider which creates/renew the
Kerberos-Ticket and AFS-Tocken for each request. These tickets are then
aviable in the enviroment for ldap and subshell-commands.
My problem is now:
When two or more request coming in at same time, the later will
overwrite the enviroment for the first. Is it possible to store the
enviroment in a per thread way or do you have other suggestions?
It works all fine when i only run one thread but it is littlebit slow
or several thread but only one user.
Thank you and keep on with your great work.
sastan
> i develop webapp to administrate a Kerbers, LDAP and AFS network. I
> was
> able to create a custom Identity-Provider which creates/renew the
> Kerberos-Ticket and AFS-Tocken for each request. These tickets are
> then
> aviable in the enviroment for ldap and subshell-commands.
>
> My problem is now:
> When two or more request coming in at same time, the later will
> overwrite the enviroment for the first. Is it possible to store the
> enviroment in a per thread way or do you have other suggestions?
The easiest thing to do is to put it on the request object:
cherrypy.request.kticket = ...
cherrypy.request.afs_token = ...
Kevin
If you want the environment to span multiple requests however, there is
a cherrypy.thread_data object per thread. You can add functions to
cherrypy.server.on_start_thread_list to have it executed on thread
creation, likewise to cherrypy.server.on_stop_thread_list to execute on
thread termination. I use these to hold my database handles so that I
have a per thread connection to sqlite (which until recently wasn't
thread safe).
So the best way i see would be to change os.environ per thread. But i
don't know how.
class ThreadLocal(threading.local, os._Environ):
def __init__(self, environ):
threading.local.__init__(self)
os._Environ.__init__(self, environ)
def on_thread_start(arg):
os.environ = ThreadLocal(os.environ)
cherrypy.server.on_start_thread_list.append(on_thread_start)
That did not work. There is still only one os.eniron.
Another idea:
* create a global lock
* aquire when specific environ is needed and block all other request
* release when done
The release need to be done after the template has rendered. So how can
i wrap tg.expose to release the lock after all work done?