Search code examples
pythonudptwistedmaster-slavereactor

Add or remove listeners to listenMulticast at runtime in twisted?


The title pretty much explains it;

Is it possible? I want to create a master-backup relationship where if the master fails, the backup takes over, becomes the master and creates its own backup and keeps running. I'm using listenMulticast to broadcast so far.

I want a behavior where I print increasing numbers in the terminal for learning purposes. If I send some sort of a interrupt signal, the master should be destroyed but from above, the relationship is re-created and the numbers keeps printing. For this purpose, I don't care if a numbers is skipped, I'm simply after the structure.

Thanks.


Solution

  • reactor.listenMulticast returns an IListeningPort. IListeningPort.stopListening stops the port from listening. IListeningPort.startListening starts it listening at the same address again.

    You can call listenMulticast, stopListening, or startListening at any time.