Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 243
Prem Mishra Avatar asked Apr 02 '26 21:04

Prem Mishra


1 Answers

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.

like image 99
Prem Mishra Avatar answered Apr 04 '26 11:04

Prem Mishra