once the executor has been constructedwe submit job to it using the root directory the submit(method immediately returns future objectwhich promises to give us result eventually the future is placed on the queue the loop then repeatedly removes the first future from the queue and inspects it if it is still runningit gets added back to the end of the queue otherwisewe check if the function raised an exception with call to future exception(if it didwe just ignore it (it' usually permission erroralthough real app would need to be more careful about what the exception wasif we didn' check this exception hereit would be raised when we called result(and could be handled through the normal try except mechanism assuming no exception occurredwe can call result(to get the return value of the function call since the function returns list of subdirectories that are not symbolic links (my lazy way of preventing an infinite loop)result(returns the same thing these new subdirectories are submitted to the executor and the resulting futures are tossed onto the queue to have their contents searched in later iteration so that' all that is required to develop future-based / -bound application under the hoodit' using the same thread or process apis we've already discussedbut it provides more understandable interface and makes it easier to see the boundaries between concurrently running functions (just don' try to access global variables from inside the future!asyncio asyncio is the current state of the art in python concurrent programming it combines the concept of futures and an event loop with the coroutines we discussed in the iterator pattern the result is about as elegant and easy to understand as it is possible to get when writing concurrent codethough that isn' saying lotasyncio can be used for few different concurrent tasksbut it was specifically designed for network / most networking applicationsespecially on the server sidespend lot of time waiting for data to come in from the network this can be solved by handling each client in separate threadbut threads use up memory and other resources asyncio uses coroutines instead of threads the library also provides its own event loopobviating the need for the several lines long while loop in the previous example howeverevent loops come with cost when we run code in an async task on the event loopthat code must return immediatelyblocking neither on / nor on long-running calculations this is minor thing when writing our own codebut it means that any standard library or third-party functions that block on / have to have non-blocking versions created