There is some visibility to the pool and queue of pending work items. To find out what is available, type poolx.__dict__ to see the structure. Read the threadpool code, it's pretty good: concurrent.futures.thread
The following creates a single-thread pool. Then he creates two works: one sleeps for 3 seconds, the other returns immediately. The pool number of pending work items is then printed.
After that, we print out the items from the work queue. In this case, the thread is already executing time.sleep(3) , so it is not in the queue. The sleep with args [0] and kwargs {} function prints because this is the next work item for the pool to run.
Kudos to @dano for a non-destructive understanding of the lineup, and @abarnert.
a source
import concurrent.futures, time poolx = concurrent.futures.ThreadPoolExecutor(max_workers=1) poolx.submit(time.sleep, 3) poolx.submit(time.sleep, 0)
exit
pending: 1 jobs threads: 1 Pending Work Queue: 1 <built-in function sleep> (0,) {}
johntellsall
source share