[Twisted-Python] Lock class using Deferreds

Christopher Armstrong radix at twistedmatrix.com
Sat Mar 6 12:18:43 MST 2004


Andy Gayton wrote:
> Christopher Armstrong wrote:
> 
>>  haven't really put much time into figuring out what's going on in 
>> this thread,
> 
> 
> Putting the Lock with similiar tools into a module I think ...

I meant, I haven't bothered enough to actually grok all the code. :)

> You twisted guys have a way of coding stuff that makes me go cross-eyed :)

Well, the app I was writing at the time was kind of weird. ;-)

> I think the following would work similiar to yours Chris ? ..
> 
> dnsRequest_Semaphore = Semaphore(20)
> for (sink, input) in source :
>     dnsRequest_Semaphore.run( request, input ).addCallback( sink )


Dunno, maybe someone else can actually grok what's going on here (I 
haven't sufficiently bothered to read your Semaphore class :P). If it is 
the same, then your Semaphore class is obviously better :) OTOH, my 
thing didn't call .next() on the source until its result was actually 
required, but this snippet is obviously queuing up the (potentially 
thousands) of operations in the Semaphore.. Probably doesn't actually 
matter.

> ???? is that right - still getting a handle on defers :) :(
> 
> the above doesn't cover the error handling you are doing though .. I 
> can't quite work out that bit ...

As the comments pointed out, the bit of error-handling was 
application-specific. I made a mistake, btw: the *first* "xxx fixme 
app-specific" wasn't actually app-specific (the 
addBoth(self._cbGotSync)) -- it was just an unfortunately 
specifically-named method. The NotSync error handling was indeed 
specific to the app I was writing.


-- 
  Twisted | Christopher Armstrong: International Man of Twistery
   Radix  |          Release Manager,  Twisted Project
---------+           http://radix.twistedmatrix.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
URL: </pipermail/twisted-python/attachments/20040306/55ffb403/attachment.sig>


More information about the Twisted-Python mailing list