CPython Multi-process

Source: Internet
Author: User

four synchronous \ Asynchronous and blocking \ non-blocking (focus)

Synchronous:

#所谓同步, that is, when a function call is made, the call does not return until the result is obtained. By this definition, the vast majority of functions are synchronous invocations. But generally speaking, we are talking about synchronous and asynchronous tasks, especially those that require other components to collaborate or need to be done in a certain amount of time. #举例: #1. Multiprocessing. Under the pool of apply #发起同步调用后, just waiting for the task at the end, do not consider whether the task is in the calculation or IO blocking, in short, a brain to the end of the task. Concurrent.futures.ProcessPoolExecutor (). Submit (func,). Result () #3. Concurrent.futures.ThreadPoolExecutor (). Submit (func,). Result ()

Asynchronous:

#异步的概念和同步相对. When an asynchronous function call is issued, the caller cannot get the result immediately. Notifies the caller by status, notification, or callback when the asynchronous function is complete. If the asynchronous function is notified by state, then the caller will need to check every time, the efficiency is very low (some beginners of multithreaded programming, always like to use a loop to check the value of a variable, which is actually a very serious error). If you are using notifications, the efficiency is high, because asynchronous functionality requires little extra action. As for the callback function, there is not much difference from the notification. #举例: #1. Multiprocessing. Pool (). Apply_async () #发起异步调用后 does not wait for the end of the task to return, instead, it immediately gets a temporary result (not the final result, possibly an encapsulated object). #2. Concurrent.futures.ProcessPoolExecutor (3). Submit (func,) #3. Concurrent.futures.ThreadPoolExecutor (3). Submit (Func,)

Blocking:

#阻塞调用是指调用结果返回之前, the current thread is suspended (such as when an IO operation is encountered). The function will activate the blocked thread only after it has obtained the result. Someone might equate blocking calls with synchronous calls, and in fact he is different. For synchronous calls, many times the current thread is still active, but logically the current function does not return. #举例: #1. Synchronous invocation: Apply a task that accumulates 100 million times, and the call waits until the task returns the result but does not block (that is, it is in the ready state to be robbed of the CPU's execute permission); #2. Blocking calls: When the socket is working in blocking mode, if the recv function is called without data, the current thread will be suspended until there is data.

Non-blocking:

#非阻塞和阻塞的概念相对应, which returns immediately before the result is not immediately available, and the function does not block the current thread.

Summary:

#1. Synchronous vs. asynchronous is about how a function/task is called: synchronization is when a process initiates a function (Task) call, waits until the function (Task) completes, and the process continues to be active. In asynchronous cases, when a process initiates a function (Task) call, it does not wait for the function to return, but continues to execute when the function returns, notifying the process that the task is complete by state, notification, event, and so on. #2. Blocking and non-blocking is for a process or thread: Blocking is suspending the process when the request is not satisfied, not blocking it does not block the current process

CPython Multi-process

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.