In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you the relevant knowledge of what the common functions of python Pool are, the content is detailed, and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Description
1. Apply_async (func [, args [, kwds]): call func using non-blocking (parallel execution, blocking mode must wait for the previous procedure to exit before executing the next procedure). Args is the parameter list transferred to func, and kwds is the keyword parameter list transferred to func.
2. Close (): close Pool so that it no longer accepts new tasks.
3. Terminate (): whether the task is completed or not, it should be terminated immediately.
4. Join (): the main process is blocked, waiting for the child process to exit, and must be used after close or terminate.
Example
# coding: utf-8import multiprocessingimport time def func (msg): print ("msg:", msg) time.sleep (3) print ("end") if _ _ name__ = "_ _ main__": cores = multiprocessing.cpu_count () pool = multiprocessing.Pool (processes=cores) print ("Adding tasks...") For i in range (cores): msg = "hello% d"% (I) pool.apply_async (func, (msg,)) # the total number of processes maintained for execution is processes. When a process finishes execution, a new process will be added to print ("Starting tasks..."). Pool.close () pool.join () # call the close function before calling join, otherwise an error will occur. After the close is executed, no new process is added to the pool,join function waiting for all child processes to finish the print ("Sub-process (es) done.") These are all the contents of the article "what are the common functions of python Pool?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.