Creating ThreadPoolExecutor

We can define our ThreadPoolExecutor object with the init constructor:

executor = ThreadPoolExecutor(max_workers=5)

We can create our ThreadPoolExecutor if we pass to the constructor the maximum number of workers as the parameter. In this example, we have defined five as the maximum number of threads, which means that this group of subprocesses will only have five threads working simultaneously.

In order to use our ThreadPoolExecutor, we can call the submit() method, which takes a function for executing that code in an asynchronous way as a parameter:
executor.submit(myFunction())

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.199.184