简体   繁体   中英

How should a Twisted AMP Deferred be cancelled?

I have a Twisted client/server application where a client asks multiple servers for additional work to be done using AMP. The first server to respond to the client wins -- the other outstanding client requests should be cancelled.

Deferred objects support cancel() and a cancellor function may be passed to the Deferred 's constructor. However, AMP's sendRemote() api doesn't support passing a cancellor function. Additionally, I'd want the cancellor function to not only stop the local request from processing upon completion but also remove the request from the remote server.

AMP's BoxDispatcher does have a stopReceivingBoxes method, but that causes all deferreds to error out (not quite what I want).

Is there a way to cancel AMP requests?

No. There is no way, presently, to cancel an AMP request.

You can't cancel AMP requests because there is no way defined in AMP at the wire-protocol level to send a message to the remote server telling it to stop processing. This would be an interesting feature-addition for AMP, but if it were to be added, you would not add it by allowing users to pass in their own cancellers; rather, AMP itself would have to create a cancellation function that sent a "cancel" command.

Finally, adding this feature would have to be done very carefully because once a request is sent, there's no guarantee that it would not have been fully processed; chances are usually good that by the time the cancellation request is received and processed by the remote end, the remote end has already finished processing and sent a reply. So AMP should implement asynchronous cancellation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM