for threadpoolexecutor
, want monitor number of threads running. seems impossible. number of active threads continually increasing. normal thread, if target function returns, thread shutdown.
import threading, concurrent.futures def test(): pass p_ac=threading.active_count() #number of threads=2 #for threads trs=[none]*10 in range(10): trs[i]=threading.thread(target=test) trs[i].start print(threading.active_count()==p_ac) #true #for executor executor=concurrent.futures.threadpoolexecutor(10) _ in range(10): executor.submit(test) print(threading.active_count()) #number of threads=12
the threadpoolexecutor
does not shutdown threads when active. threadpoolexecutor(x)
creates x
threads , keeps them alive until shutdown executor via executor.shutdown()
or executor decides doesn't need many threads. anyway x
expected amount of threads if executor active.
thanks for sharing
ReplyDeletePython Online Training
Data Science Online Training