I am curious about executor.shutdown method, and I was trying to find some information about it...
according to python docs,
**shutdown(wait=True, *, cancel_futures=False)
If wait is True then this method will not return until all the pending futures are done executing and the resources associated with the executor have been freed. If wait is False then this method will return immediately and the resources associated with the executor will be freed when all pending futures are done executing. Regardless of the value of wait, the entire Python program will not exit until all pending futures are done executing.**
but I could not understand what "this method will return" means in the paragraph...
does executor.shutdown method returns any value??
for example, in this code
import concurrent.futures
import time
def pafter(t):
time.sleep(t)
print('Hi)
with concurrent.futures.ThreadPoolExecutor(5) as e:
e.submit(pafter, 2)
print('With returned')
does shutdown method return any value??
CodePudding user response:
shutdown()
does not explicitly return a value (meaning, if you captured the return value, it would be None
, like any other function or method that does not return a value).
All the documentation is referring to concerning the wait
argument is that if wait=False
, shutdown()
will return back to the caller immediately, and if wait=True
, shutdown()
will wait to return until after the futures have completed.
The relevant portion of the code in shutdown()
is literally just this:
if wait:
for t in self._threads:
t.join()
It joins all of the threads and returns after they have exited.