In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to initialize the process pool Pool in python". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to initialize the process pool Pool in python" can help you solve your doubts.
Description
1. When initializing Pool, you can specify the number of processes.
2. When a new request is submitted to Pool, a new process is created to execute the request if the pool is not full.
3. If the number of processes in the pool reaches the specified value, wait for the request until the end of the process in the pool, and perform the new task with the previous process.
Example
#-*-coding:utf-8-*-import os, time, randomfrom multiprocessing import Pool def worker (msg): t_start = time.time () print ("% s starts execution, process number is% d"% (msg,os.getpid ()) # random.random () randomly generates floating point numbers time.sleep (random.random () * 2) t_stop = time.time () print (msg, "execution complete Time-consuming% 0.2f\ n "% (t_stop-t_start)) def main (): po = Pool (3) # define a process pool Number of processes 3 for i in range (0J10): # Pool (). Apply_async (target to be called, (parameter passed to target meta-ancestor,) # each cycle will use idle child processes to call target po.apply_async (worker, (I,)) print ("- start----") po.close () # close the process pool After closing, po will no longer receive new requests po.join () # waiting for all child processes in po to complete execution. It must be placed after the close statement print ("- end-") if _ _ name__ = = "_ _ main__": main () reads here, this article "how to initialize process pool Pool in python" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about the articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.