自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Python Library中的Semaphore操作方案詳解

開發(fā) 后端
西安免的文章就是對Python Library這一計算機(jī)語言在實際操作過程中應(yīng)用方案的具體介紹,以下是文章相關(guān)內(nèi)容的的簡介。

Python Library作為計算機(jī)語言中常用的語言,很多人都會接觸到Python Library中的Semaphore這一計算機(jī)語言,一下的文章就是對其實際應(yīng)用操作方案的具體介紹,希望你瀏覽完以下的文章會對你有所幫助。

Python Library Semaphore和 .NET Semaphore 一樣,限制可同時訪問某一資源的線程數(shù)。

 

  1. lock = Semaphore(2)  
  2. def test():  
  3. with lock:  
  4. for i in range(5):  
  5. print currentThread().name, i  
  6. sleep(1)  
  7. for i in range(5):  
  8. Thread(target = test).start()   

 

輸出:

  1. $ ./main.py 

 

Thread-1 0 <--- Thread-1 和 Thread-2 獲得鎖
 

  1. Thread-2 0  
  2. Thread-1 1  
  3. Thread-2 1  
  4. Thread-1 2  
  5. Thread-2 2  
  6. Thread-1 3  
  7. Thread-2 3  
  8. Thread-1 4  
  9. Thread-2 4 

Thread-3 0 <--- Thread-3 和 Thread-4 獲得鎖
 

  1. Thread-4 0  
  2. Thread-3 1  
  3. Thread-4 1  
  4. Thread-3 2  
  5. Thread-4 2  
  6. Thread-3 3  
  7. Thread-4 3  
  8. Thread-3 4  
  9. Thread-4 4 

Thread-5 0 <--- Thread-5 獲得鎖
 

  1. Thread-5 1  
  2. Thread-5 2  
  3. Thread-5 3  
  4. Thread-5 4 

以上就是對Python Library中的Semaphore實際應(yīng)用操作方案詳解的相關(guān)介紹。

【編輯推薦】

  1. Python運行效率優(yōu)于C語言的功能簡介
  2. PythonS60手機(jī)中搭建手機(jī)運行平臺的五個步驟
  3. Python字符串中的mapping的功能介紹
  4. Python字符串中字符的大寫與小寫的變化
  5. Python數(shù)組中實際應(yīng)用的數(shù)據(jù)結(jié)構(gòu)的操作方案
責(zé)任編輯:佚名 來源: 博客園
相關(guān)推薦

2010-03-17 13:33:04

Python Libr

2010-03-17 13:14:00

Python Libr

2010-03-17 12:20:15

Python Libr

2010-03-15 17:56:24

Python字典

2010-03-17 12:37:51

Python定時器

2010-03-17 15:01:24

Python復(fù)制文件

2010-03-23 14:54:27

Python目錄文件

2010-03-11 19:45:09

Python邏輯

2010-03-22 10:11:28

Python Libr

2010-04-12 14:44:06

Oracle Impd

2010-03-17 16:27:39

Python矩陣轉(zhuǎn)置

2024-01-03 10:00:11

Prometheus指標(biāo)Go

2010-03-15 15:38:47

Python運行

2010-03-16 10:00:37

Python函數(shù)

2010-03-16 10:58:35

Python字符串

2010-03-16 16:47:25

Python數(shù)組

2010-03-29 10:55:38

Oracle優(yōu)化

2010-03-18 11:06:18

Python stuc

2010-03-17 10:58:47

Python學(xué)習(xí)筆記

2010-02-26 14:29:32

Python 工具
點贊
收藏

51CTO技術(shù)棧公眾號