Python3 "Modules" Concurrent.futures modules, thread pool process pools

Source: Internet
Author: User

The Python standard library provides us with the threading and multiprocessing modules to write the corresponding multithreaded/multi-process code, but when the project reaches a certain scale, frequent creation/destruction of processes or threads is very resource-intensive, At this point we are going to write our own pool of threads/processes to change the time in space. But starting with Python3.2, the standard library provides us with the Concurrent.futures module, which provides Threadpoolexecutor and processpoolexecutor two classes, enabling the threading and multiprocessing One-step abstraction that provides direct support for writing thread pool/process pools. module: Threadpoolexecutor,processpoolexecutor Subclass of Concurrent.futures module Simple example:
From concurrent.futures Import threadpoolexecutor,processpoolexecutorimport timedef Task (ARG1,ARG2):    print (arg1 , arg2)    time.sleep (1) # pool = Processpoolexecutor (ten) pool = Threadpoolexecutor (ten) for I in range:    Pool.submit (Task,i,i)

  

Python3 "Modules" Concurrent.futures modules, thread pool process pools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.