Prem Mishra
Prem Mishra

Reputation: 41

Nothing is printed while using concurrent.futures

I want to make a process run parallelly, so I am using concurrent.futures . The problem is that it does not execute the function hello().

import time
import concurrent.futures
def hello(name):
    print(f'hello {name}')
    sleep(1)

if __name__ == "__main__":
    t1=time.perf_counter()
    names=["Jack","John","Lily","Stephen"]


    with concurrent.futures.ProcessPoolExecutor() as executor:
        executor.map(hello,names)

    t2=time.perf_counter()
    print(f'{t2-t1} seconds')

Output

0.5415315 seconds

Upvotes: 3

Views: 1401

Answers (1)

Prem Mishra
Prem Mishra

Reputation: 41

After going through the concurrent.futures documentation I found that ProcessPoolExecutor does not work in the interactive interpreter. So you need to make a file and run it via command prompt/bash shell.

Upvotes: 1

Related Questions