per thread environ

1 view
Skip to first unread message

sastan

unread,
Jun 20, 2006, 5:19:44 AM6/20/06
to TurboGears
Hello,

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

Kevin Dangoor

unread,
Jun 20, 2006, 6:43:30 AM6/20/06
to turbo...@googlegroups.com
On Jun 20, 2006, at 5:19 AM, sastan wrote:

> 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

Joseph Tate

unread,
Jun 20, 2006, 8:38:16 AM6/20/06
to TurboGears

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).

sastan

unread,
Jun 23, 2006, 2:05:47 AM6/23/06
to TurboGears
Thanks for your response. I already save these ticket/token in the
request. My problem now is that they must be set in the environ with
os.environ or os.putenv. I can not find a way to change only the
environ for the current thread. Creating a complete new environ for
every shell-call takes to long (0.1 sec for each call and sometimes i
have a lot).

So the best way i see would be to change os.environ per thread. But i
don't know how.

sastan

unread,
Jun 23, 2006, 2:39:54 AM6/23/06
to TurboGears
I tried to modify os.environ with a new class:

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?

Reply all
Reply to author
Forward
0 new messages