Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python concurrent.futures.ProcessPoolExecutor multiple arguments

import concurrent.futures


def hello(first_name: str, last_name: str) -> None:
    """Prints a friendly hello with first name and last name"""
    print('Hello %s %s!' % (first_name, last_name))


def main() -> None:
    """Examples showing how to use ThreadPoolExecutor and executer.map
    sending multiple arguments to a function"""

    # Example 1: Sending multiple arguments using tuples
    # Define tuples with sequential arguments to be passed to hello()
    args_names = (
        ('Bruce', 'Wayne'),
        ('Clark', 'Kent'),
        ('Diana', 'Prince'),
        ('Barry', 'Allen'),
    )
    with concurrent.futures.ThreadPoolExecutor() as executor:
        # Using lambda, unpacks the tuple (*f) into hello(*args)
        executor.map(lambda f: hello(*f), args_names)

    print()

    # Example 2: Sending multiple arguments using dict with named keys
    # Define dicts with arguments as key names to be passed to hello()
    kwargs_names = (
        {'first_name': 'Bruce', 'last_name': 'Wayne'},
        {'first_name': 'Clark', 'last_name': 'Kent'},
        {'first_name': 'Diana', 'last_name': 'Prince'},
        {'first_name': 'Barry', 'last_name': 'Allen'},
    )
    with concurrent.futures.ThreadPoolExecutor() as executor:
        # Using lambda, unpacks the dict (**f) into hello(**kwargs)
        executor.map(lambda f: hello(**f), kwargs_names)


if __name__ == '__main__':
    main()
Comment

PREVIOUS NEXT
Code Example
Python :: get value of list separately python 
Python :: subprocess readline blocking problem 
Python :: create date by column values pandas 
Python :: variance in machine learning 
Python :: dropping original values after merging scaled values 
Python :: django error column last_login cannot be null 
Python :: 1042 uri solution 
Python :: create empty dataframe and concat 
Python :: loc condition on first 3 columns of dataframe 
Python :: upload file to SQL server pyodbc python 
Python :: python google translator 
Python :: django Account has no customer 
Python :: how to create a sub project in django 
Python :: python dataframe update if not new row 
Python :: how to resize image with pillow in django 
Python :: python print list in dictionary 
Python :: qlabel click python 
Python :: python get text between two points 
Python :: how to check what version of pygame you have instaled 
Python :: print less than specific number in one row python 
Python :: how to get the words inside a entry tkinter python 
Python :: mk virtual env 
Python :: plot idl 
Python :: top automotive blogs 
Python :: celery subprocess 
Python :: getting range lowest and highest values from np array 
Python :: how to use Py-agender for projects 
Python :: dargon 
Python :: fforeveer loop python 
Python :: python dict ffrom lists 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =