def _retry_on_port_collision(reason, add, cleanup):
 reason.trap(AddressInUse)
 (ip, port) = reason.value.address
 used_by = _find_process_name(port)
 ADDRESS_IN_USE(ip=ip, port=port, name=used_by).write()
 d = cleanup()
 d.addCallback((lambda ignored: add()))
 return d

def _retry_on_port_collision ( reason , add , cleanup ) : reason . trap ( AddressInUse ) ( ip , port ) = reason . value . address used_by = _find_process_name ( port ) ADDRESS_IN_USE ( ip = ip , port = port , name = used_by ) . write ( ) d = cleanup ( ) d . addCallback ( ( lambda ignored : add ( ) ) ) return d
cleanup and re-add a container if it failed to start because of a port collision .