上QQ阅读APP看书,第一时间看更新
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())