python 3.x - python3 concurrent.futures how to stop a threadPool -
hope there way i'm looking :
i have python3 concurrent.futures threadpoolexecutor object. multi threading used send lot of http requests concurrently.
i able stop entire pool of threads (having threads stop working) when keyboardinterrupt exception caught. basically, program can summed following piece of code :
import time,concurrent.futures def waitprint() : time.sleep(1) print("working ..") return true future_results = [] executor = concurrent.futures.threadpoolexecutor(max_workers=4) in range(0,100) : future_results.append(executor.submit(waitprint)) try : future in concurrent.futures.as_completed(future_results) : print(future.result()) except keyboardinterrupt : print("stopped user") executor.shutdown(wait=false) print("finished")
i thought executor.shutdown
function have stopped pool , associated threads it's not case, when hit ctrl+c, hundred threads still created writing down "working ..." in terminal...
is there way me stop execution of threads before launched ?
thanks help, more info program : github.com/almandin/fuxploider
Comments
Post a Comment