def force_leave_swarm(client):
 while True:
  try:
   return client.swarm.leave(force=True)
  except docker.errors.APIError as e:
   if (e.explanation == 'context deadline exceeded'):
    continue
   else:
    return

def force_leave_swarm ( client ) : while True : try : return client . swarm . leave ( force = True ) except docker . errors . APIError as e : if ( e . explanation == 'context deadline exceeded' ) : continue else : return
actually force leave a swarm .