Python GIL (Application of threads and processes), pythongil

Source: Internet
Author: User

Python GIL (Application of threads and processes), pythongil

1. GIL: http://www.tuicool.com/articles/7zIra2r

Http://www.zhihu.com/question/23474039

Ii. thread lock

In the threading module, two types of locks are defined: threading. Lock and threading. RLock. There is a slight difference between them, which can be explained by comparing the following two pieces of code:

The main difference between the two types of OSS is that RLock allows multiple acquire requests in the same thread. But Lock does not allow this situation. NOTE: If RLock is used, the acquire and release must appear in pairs. That is, the acquire and release must be called n times to release the occupied lock. Threading. Condition

Condiftion can be understood as an advanced Lock. It provides more advanced functions than Lock and RLock, allowing us to control complicated thread synchronization problems. Threadiong. Condition maintains a lock object internally (RLock by default). You can pass the lock object as a parameter when creating a Condigtion object. Condition also provides the acquire and release methods, which have the same meaning as the acquire and release methods of the lock. In fact, it is just a simple method to call the corresponding internal Lock Object. Condition also provides the following methods (Note: These methods can be called only after the lock is occupied (acquire); otherwise, a RuntimeError exception will be reported .) :

Condition. wait ([timeout]):

The wait method releases the internal lock and the thread is suspended until the notification is wake up or times out (if the timeout parameter is provided ). When the thread is awakened and the lock is re-occupied, the program continues to run.

Condition. Condition y ():

Wake up a suspended thread (if a suspended thread exists ). Note: The notify () method does not release the occupied lock.

Condition. policy_all ()
Condition. policyall ()

Wake up all suspended threads (if any ). Note: These methods do not release the occupied locks.

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.