Multiprocessing pool



    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, (["A", 5], ["B", 2], ["C", 1], ["D", 3]))
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.