Multiprocessing pool

    0

    7

    Python public recipes

    The code defines a function work_function that takes an iterable of work_data objects. In the pool_handler function, the p variable is set to a Pool object. The pool will have two threads. The first thread will use the work_function to process the first work_data object, the second thread will use the work_function to process the second work_data object, and so on.

    Shortcut: multiprocessing.pool

    from multiprocessing import Pool
    import time
    
    def work_function(work_data):
    	print(f"Processing {work_data}")
    def pool_handler():
      p = Pool(numthreads)  # Number of thread in the pool
      p.map(work_function, (["A", 5], ["B", 2], ["C", 1], ["D", 3]))
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.