[Twisted-Python] Lock class using Deferreds

Andy Gayton andy at thecablelounge.com
Sat Mar 6 01:46:59 MST 2004


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

> class DeferredQueue:
> 
>     MAX_REQUESTS = 20

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

You're right - it is a bit different.  DeferredQueue takes a known 
amount of work you've got to get through and feeds it out at a 
controlled rate - the modified Itamar's Lock is a similiar control but 
accepts spontaneous requests for work.

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 )

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

Andy.




More information about the Twisted-Python mailing list