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.