[Twisted-Python] Re: [Twisted-commits] *With() methods; refactor/rearrangement of various internal classes
![](https://secure.gravatar.com/avatar/b3407ff6ccd34c6e7c7a9fdcfba67a45.jpg?s=120&d=mm&r=g)
On Thu, Jan 30, 2003 at 03:19:34PM -0600, exarkun CVS wrote: [..snip..]
Should tcp.py import t.p.compat (ugh)? Or is it safe to assume that service names for ports will always be ascii (in which case we change that to "if port == types.StringTypes")? -Andrew.
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Fri, 31 Jan 2003 17:23:24 +1100, Andrew Bennetts <andrew-twisted@puzzling.org> wrote:
I think not. This has been the recommended style for a while. Python 2.1.3 (#1, Jan 3 2003, 13:08:57) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import types >>> isinstance(1, types.StringType) 0 >>> isinstance(1, types.IntType) 1 -- | <`'> | Glyph Lefkowitz: Travelling Sorcerer | | < _/ > | Lead Developer, the Twisted project | | < ___/ > | http://www.twistedmatrix.com |
![](https://secure.gravatar.com/avatar/56e4cc78ea7fcf3bb37888ebf23bc1f0.jpg?s=120&d=mm&r=g)
On Fri, Jan 31, 2003 at 06:30:06PM +1100, Andrew Bennetts wrote:
Yea, thanks. Fix has been checked in. (Not only is StringTypes not in 2.1, but isinstance() doesn't work on tuples there either ;) Jp -- C/C++/Java/Perl/Python/Smalltalk/PHP/ASP/XML/Linux (User+Admin) Genetic Algorithms/Genetic Programming/Neural Networks Networking/Multithreading/Legacy Code Maintenance/OpenGL See my complete resume at http://intarweb.us:8080/ -- up 46 days, 7:49, 5 users, load average: 0.55, 0.34, 0.16
![](https://secure.gravatar.com/avatar/43fca93c2d82d8333ab5b47ae0ecf1e3.jpg?s=120&d=mm&r=g)
Hello all, I have been playing with pb for a few days now and have run into a bit of a snag. I support of my pb based server I created an authorizor that did a little db based authorization. At first I had it returning the ident object, but then I realized (after a few attribute errors) that it should be returning a deffered object. Then I saw the mention of dbcred from the enterprise package. That help allot and I actually got it working by pulling some code from dbcred. 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. 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. Thanks, Eric __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com
![](https://secure.gravatar.com/avatar/b3407ff6ccd34c6e7c7a9fdcfba67a45.jpg?s=120&d=mm&r=g)
On Fri, Jan 31, 2003 at 12:09:23PM -0800, Eric Merritt wrote:
[..snip..]
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.
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 :) -Andrew.
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
On Fri, 31 Jan 2003 17:23:24 +1100, Andrew Bennetts <andrew-twisted@puzzling.org> wrote:
I think not. This has been the recommended style for a while. Python 2.1.3 (#1, Jan 3 2003, 13:08:57) [GCC 2.95.4 20011002 (Debian prerelease)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import types >>> isinstance(1, types.StringType) 0 >>> isinstance(1, types.IntType) 1 -- | <`'> | Glyph Lefkowitz: Travelling Sorcerer | | < _/ > | Lead Developer, the Twisted project | | < ___/ > | http://www.twistedmatrix.com |
![](https://secure.gravatar.com/avatar/56e4cc78ea7fcf3bb37888ebf23bc1f0.jpg?s=120&d=mm&r=g)
On Fri, Jan 31, 2003 at 06:30:06PM +1100, Andrew Bennetts wrote:
Yea, thanks. Fix has been checked in. (Not only is StringTypes not in 2.1, but isinstance() doesn't work on tuples there either ;) Jp -- C/C++/Java/Perl/Python/Smalltalk/PHP/ASP/XML/Linux (User+Admin) Genetic Algorithms/Genetic Programming/Neural Networks Networking/Multithreading/Legacy Code Maintenance/OpenGL See my complete resume at http://intarweb.us:8080/ -- up 46 days, 7:49, 5 users, load average: 0.55, 0.34, 0.16
![](https://secure.gravatar.com/avatar/43fca93c2d82d8333ab5b47ae0ecf1e3.jpg?s=120&d=mm&r=g)
Hello all, I have been playing with pb for a few days now and have run into a bit of a snag. I support of my pb based server I created an authorizor that did a little db based authorization. At first I had it returning the ident object, but then I realized (after a few attribute errors) that it should be returning a deffered object. Then I saw the mention of dbcred from the enterprise package. That help allot and I actually got it working by pulling some code from dbcred. 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. 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. Thanks, Eric __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com
![](https://secure.gravatar.com/avatar/b3407ff6ccd34c6e7c7a9fdcfba67a45.jpg?s=120&d=mm&r=g)
On Fri, Jan 31, 2003 at 12:09:23PM -0800, Eric Merritt wrote:
[..snip..]
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.
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 :) -Andrew.
participants (4)
-
Andrew Bennetts
-
Eric Merritt
-
Glyph Lefkowitz
-
Jp Calderone