multiprocessing the following sample program illustrates the basic use of the pool and the map(method from multiprocessing import pool def worker( )print('in worker with'xreturn def main()with pool(processes= as poolprint(pool map(worker[ ])if __name__ ='__main__'main(note that the pool object must be closed once you have finished with itwe are therefore using the 'with asstatement described earlier in this book to handle the pool resource cleanly (it will ensure the pool is closed when the block of code within the with as statement is completedthe output from this program is in worker with in worker with in worker with in worker with in worker with in worker with [ as can be seen from this output the map(function is used to run six different instances of the worker(function with the values provided by the list of integers each instance is executed by worker process managed by the pool howevernote that the pool only has worker processesthis means that the last two instances of the worker function must wait until two of the worker processes have finished the work they are doing and can be reused this can act as way of throttlingor controllinghow much work is done in parallel variant on the map(method is the imap_unordered(method this method also applies given function to an iterable but does not attempt to maintain the order of the results the results are accessible via the iterable returned by the function this may improve the performance of the resulting program the following program modified the worker(function to return its result rather than print it these results are then accessible by iterating over them as they are produced via for loop