[Twisted-Python] PB , authorizor, getIdentRequest

Andrew Bennetts andrew-twisted at puzzling.org
Fri Jan 31 19:39:08 EST 2003

On Fri, Jan 31, 2003 at 12:09:23PM -0800, Eric Merritt wrote:
>  At this point you could authorize yourself based on
> the database and make calls to the server, and all was
> good.
>  At that point I was pretty happy but I noticed that
> within the code for dbcred it makes a call to
> threads.defferToTread. Me being me, I thought to
> myself 'I am not using threads, so why am I using
> this?' and I took it out. So I changed it, and am
> simply returning a deffered object that has a callback
> that returns the identity object, and it fails. In any
> case, I was wondering if any one had any idea of why
> removing the thread specific code causes it to fail.

Standard Python DB-API 2.0 modules are synchronous, i.e. they block while
they wait for results.  dbcred.DatabaseAuthorizer uses
twisted.enterprise.adbapi to talk with your database, and adbapi uses
threads so that it can present an asynchronous interface to the database
while using standard DB-API compliant modules (see the Introduction to
Twisted Enterprise HOWTO for details).

So unfortunately, database access does involve threads -- but Twisted takes
care of it all for you behind the scenes when you use twisted.enterprise, so
you can basically pretend they don't exist :)

I don't know why your specific change would fail, but it would cause
problems due to blocking -- remember that database queries can take an
arbitarily long amount of time to be processed, particularly under load.  My
advice is to just use the standard dbcred module as-is, if you can.

> Also in a completly unrelated question, is it possible
> for the server to make calles on the client? I figure
> this is possible by passing a referencable object to
> the server perspective, but I thought I would get a
> little advice before I started playing with it.

I know you can do this by getting the client to pass the server a reference
to itself, which the server can then do .callRemote on (just as the client
can do .callRemote on the server).  I'm not sure if there's a better way;
someone who knows more about PB that I do will have to tell you :)


More information about the Twisted-Python mailing list