How do I check if the ProcessPoolExecutor is full?

Viewed 32

We want to know if the executor has reached max_workers. Is there a simple way to find out how many workers are running in the following code?

import concurrent.futures


def dummy_process(arg_a, arg_b):
    print("ml_process", arg_a, arg_b)
    time.sleep(5)

executor = concurrent.futures.ProcessPoolExecutor(max_workers=2)

def main():
    while True:
        executor.submit(dummy_process, "test_a", "test_b")

if __name__ == "__main__":
    main()
1 Answers

use try except

import concurrent.futures


def dummy_process(arg_a, arg_b):
    print("ml_process", arg_a, arg_b)
    time.sleep(5)

executor = concurrent.futures.ProcessPoolExecutor(max_workers=2)

def main():
    while True:
        try:
           executor.submit(dummy_process, "test_a", "test_b")
        except:
           print("Pool Executer is Full")

if __name__ == "__main__":
    main() 
Related