from concurrent.futures import ThreadPoolExecutor
import threading
def task(n):
print("Processing {} - {}".format(n, threading.current_thread()))
def main():
print("Starting ThreadPoolExecutor")
with ThreadPoolExecutor(max_workers=3) as executor:
future = executor.submit(task, (2))
future = executor.submit(task, (3))
future = executor.submit(task, (4))
print("All tasks complete")
if __name__ == '__main__':
main()
Output:
Starting ThreadPoolExecutor
Processing 2 - <Thread(ThreadPoolExecutor-0_0, started daemon 140052642395904)>
Processing 3 - <Thread(ThreadPoolExecutor-0_1, started daemon 140052634003200)>
Processing 4 - <Thread(ThreadPoolExecutor-0_2, started daemon 140052625610496)>
All tasks complete
No comments:
Post a Comment