Python full stack development, Day41 (threading concept, threading features, process and thread relationships, threading and Python theory knowledge, threading creation)

Source: Internet
Author: User

Yesterday's content review
Queue    queue: FIFO, data process secure    Queue implementation: Pipeline + lock    producer Consumer Model: Resolve data supply and demand unbalanced pipeline    bidirectional communication, data process insecure    Eoferror:        Pipeline is a reference count by the operating system        must be closed in all processes before you can generate Eoferror exception data sharing (infrequently used)    Manager    list dict   data process unsafe process pool    storage container for process    at the beginning of the process creation, creating a fixed number of processes    will be recycled by multiple tasks    saving process creation and destruction time overhead reduces the amount of    pressure and process pool differences in the operating system scheduling process    semaphore: N Tasks Open N processes ,        But there can only be a fixed number of processes at the same time in the execution        process waiting to be executed    process pool: N tasks to open a fixed number of processes        so only a fixed number of processes in the execution of the        task is waiting to be executed

The queue is a built-in lock, so it is safe for other applications to call it.

When it comes to manual locking, it is unsafe. Commonly used is the message middleware

Galena with no return value

Close and join paired use

Import timefrom multiprocessing Import pooldef Wahaha (i):    time.sleep (1)    print (' * ' * i) if __name__ = = ' __main__ ':    p = Pool (5)  # The recommended number is CPU cores +1    for I in range (5):        P.apply_async (Func=wahaha, args= (i,))    P.close ()  # No more new tasks to submit    P.join ()  # Wait for the tasks in the pool to finish executing

Execution output:

Python full stack development, Day41 (threading concept, threading features, process and thread relationships, threading and Python theory knowledge, threading creation)

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.