running multiple futures first_exception the function will return when any future finishes by raising an exception if no future raises an exceptionthen it is equivalent to all_completed all_completed the function will return when all futures finish or are cancelled the wait(function returns two sets done and not_done the first set contains the futures that completed (finished or were cancelledbefore the wait completed the second setthe not_donescontains uncompleted futures we can use the wait(function to modify out previous example so that we no longer rely on future finishing lastfrom concurrent futures import processpoolexecutor from concurrent futures import wait from time import sleep def worker(msg)for in range( , )print(msg,end=''flush=truesleep( return print('starting setting up pool'pool processpoolexecutor( futures [print('submitting futures'future pool submit(worker' 'futures append(future future pool submit(worker' 'futures append(future future pool submit(worker' 'futures append(future future pool submit(worker' 'futures append(future print('waiting for futures to complete'wait(futuresprint('\nall done'the output from this isstarting setting up pool submitting futures waiting for futures to complete abcabcabcabcabcabcbcacbacbabcadddddddddd all done note how each future is added to the list of futures which is then passed to the wait(function