Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

multiprocessing pool pass additional arguments

#!/usr/bin/env python3
from functools import partial
from itertools import repeat
from multiprocessing import Pool, freeze_support

def func(a, b):
    return a + b

def main():
    a_args = [1,2,3]
    second_arg = 1
    with Pool() as pool:
        L = pool.starmap(func, [(1, 1), (2, 1), (3, 1)])
        M = pool.starmap(func, zip(a_args, repeat(second_arg)))
        N = pool.map(partial(func, b=second_arg), a_args)
        assert L == M == N

if __name__=="__main__":
    freeze_support()
    main()
Comment

PREVIOUS NEXT
Code Example
Python :: stutter function in python 
Python :: I have string index in pandas DataFrame how can I select by startswith? 
Python :: floating point python 
Python :: how to declare a class in python 
Python :: turn columns into one column as list python 
Python :: _set in django 
Python :: timedelta python days 
Python :: User serializer in django rest framework 
Python :: sql like equivalent in python 
Python :: detailview 
Python :: deleting a file using python 
Python :: dataframe subtract value from previous row 
Python :: install poetry on linux 
Python :: pandas check if any of the values in one column exist in another 
Python :: four digit representation python 
Python :: select rows in python 
Python :: argmax implementation 
Python :: pandas loc for list 
Python :: ValueError: query data dimension must match training data dimension 
Python :: pip install mod_wsgi error 
Python :: binary python 
Python :: python how to draw a circle 
Python :: python try else 
Python :: discord.py get id of sent message 
Python :: how to add subtitle to plot in python 
Python :: python PyDrive service account credentials 
Python :: python enum to int 
Python :: Replace all the empty rows in the column with the value that you have identified 
Python :: how to define a class in python 
Python :: how to find avrage python 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =