Re: [Twisted-Python] deferreds and hung connections
--- Jp Calderone <exarkun@divmod.com> wrote:
As was recently mentioned on the list, timeout support needs to be part of the result-generating API. Luckily, in the case of getPage, it is, as demonstrated by this manhole session:
>>> from twisted.web import client >>> client.getPage('http://google.com', timeout=0.001) <Deferred #0> Deferred #0 failed: 'Getting http://google.com took longer than 0.001 seconds.' >>>
Thanks for the pointer, Jp. I just stumbled on some of the threads on the mailing list stretching back to as far as 2002 about whether being able to cancel Deferreds was a good idea or not. So the above solution works. Where do I catch, or otherwise react to, the error printed above? When the Deferred times out, is there a way to inject another callback in there ("timeoutcallback"?) so that I can do some processing on timeout? It looks like I could override HTTPClientFactory's timeout() method if I had a handle to it, but getPage() doesn't give me access. Am I barking up the wrong tree? Lenny __________________________________ Celebrate Yahoo!'s 10th Birthday! Yahoo! Netrospective: 100 Moments of the Web http://birthday.yahoo.com/netrospective/
On Wed, 9 Mar 2005 11:17:58 -0800 (PST), Lenny G Arbage <alengarbage@yahoo.com> wrote:
<Deferred #0> Deferred #0 failed: 'Getting http://google.com took longer than 0.001 seconds.' >>>
Thanks for the pointer, Jp. I just stumbled on some of the threads on the mailing list stretching back to as far as 2002 about whether being able to cancel Deferreds was a good idea or not.
So the above solution works. Where do I catch, or otherwise react to, the error printed above? When the Deferred times out, is there a way to inject another callback in there ("timeoutcallback"?) so that I can do some processing on timeout?
It's just a regular errback. Handle it with d.addErrback(myHandler). -- Twisted | Christopher Armstrong: International Man of Twistery Radix | -- http://radix.twistedmatrix.com | Release Manager, Twisted Project \\\V/// | -- http://twistedmatrix.com |o O| | Founding Member, Hobart Hacking Society w----v----w-+ -- http://hackingsociety.org/chapters/hash
I'm trying to set a python property on a PB client descended from pb.Referenceable, but it seems that properties don't work on old style classes and that Referenceable is descended from Jellyable, an old style class. Moreover, I see this is still true for 2.0.0a2... Is there any intention of switching to new classes, or should I just hack around this? -Jasper
Jasper wrote:
I'm trying to set a python property on a PB client descended from pb.Referenceable, but it seems that properties don't work on old style classes and that Referenceable is descended from Jellyable, an old style class. Moreover, I see this is still true for 2.0.0a2...
Is there any intention of switching to new classes, or should I just hack around this?
Turns out that the simple hack of Client( object, pb.Referenceable ) seems to work. Sorry for the trouble! -Jasper
On Mar 9, 2005, at 9:15 PM, Jasper wrote:
Jasper wrote:
I'm trying to set a python property on a PB client descended from pb.Referenceable, but it seems that properties don't work on old style classes and that Referenceable is descended from Jellyable, an old style class. Moreover, I see this is still true for 2.0.0a2...
Is there any intention of switching to new classes, or should I just hack around this?
Turns out that the simple hack of Client( object, pb.Referenceable ) seems to work. Sorry for the trouble!
You really don't want to do that. Then, if pb.Referenceable ever does become a new-style class (for example because a new version of python gets rid of oldstyle classes, or because twisted is changed), then you'll get an MRO construction error. Always put object last in the inheritance line. E.g.: class Foo: pass class Bar(object, Foo): pass # Fine class Foo(object): pass class Bar(object, Foo): pass # BOOM James
James Y Knight wrote:
On Mar 9, 2005, at 9:15 PM, Jasper wrote:
Jasper wrote:
I'm trying to set a python property on a PB client descended from pb.Referenceable, but it seems that properties don't work on old style classes and that Referenceable is descended from Jellyable, an old style class. Moreover, I see this is still true for 2.0.0a2...
Is there any intention of switching to new classes, or should I just hack around this?
Turns out that the simple hack of Client( object, pb.Referenceable ) seems to work. Sorry for the trouble!
You really don't want to do that. Then, if pb.Referenceable ever does become a new-style class (for example because a new version of python gets rid of oldstyle classes, or because twisted is changed), then you'll get an MRO construction error. Always put object last in the inheritance line.
E.g.: class Foo: pass class Bar(object, Foo): pass # Fine
class Foo(object): pass class Bar(object, Foo): pass # BOOM
Actually, I prefer it to blow up to help remember when to stop using this ugly comment requiring hack.. I have absolute control over the version of Python and Twisted I'm using, and so the worst that can happen is that I'll have to change a single line of code when and if I upgrade to such a version of Twisted or Python. -Jasper
Jasper <jasper@peak.org> writes:
Turns out that the simple hack of Client( object, pb.Referenceable ) seems to work. Sorry for the trouble!
One problem you might then run into is that the jelly layer doesn't like passing new style objects. In our case we just patched jelly.py to handle them (using a suggested change from twisted bug 462 I believe). -- David
participants (5)
-
Christopher Armstrong
-
David Bolen
-
James Y Knight
-
Jasper
-
Lenny G Arbage