# Pastebin i0ZtAz8y def wait_done_or_dead(futs, dead, check_timeout=1): while True: _done, not_done = futures.wait(futs, timeout=check_timeout) if len(not_done) == 0: break if dead.is_set(): for fut in not_done: # This may not actually be able to cancel, but try to # if we can. fut.cancel()