Python---Basics review (10) Processes and threads (custom thread pool, context Manager, and use of the association)

Source: Internet
Author: User

Foreplay: Understand the next queue queues before you make a custom thread pool

The queue can hold the underlying data type, or it can hold special data types such as classes, objects, etc.

 fromQueue Import Queueclasst:def __init__ (self,num): Self.num=num def printf (self): print (Self.num,id (self.num))if__name__ = ="__main__": Queue= Queue (0) Num= A queue.put (num) #可以存放基础数据类型t=T (num) queue.put (t) #可以存放对象CLS=T queue.put (CLS) #可以存放类DT= Queue.Get() print (ID (dt), dt,type (DT)) #1385649280  A<class 'int'>DT= Queue.Get() print (ID (dt), dt,type (DT)) #7652128<__main__. TObjectAt0x000000000074c320> <class '__main__. T'>DT= Queue.Get() print (ID (dt), dt,type (DT)) #18042264<class '__main__. T'> <class 'type'>

The functions that the thread pool should have:
    1. Create a thread pool first,
    2. And then to get the data, if you have to take it directly,
    3. If not, you need to block the wait until there is data to arrive
    4. The thread pool can set the specified size
    5. To meet the above "blocking" requirements, set the size of the data structure, we can use the queue
Simple version (Low):

Python---Basics review (10) Processes and threads (custom thread pool, context Manager, and use of the association)

Related Article

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.