国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語(yǔ)言編程技術(shù)及教程分享平臺(tái)!
分類(lèi)導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - Python實(shí)現(xiàn)線程池代碼分享

Python實(shí)現(xiàn)線程池代碼分享

2020-07-16 10:52Python教程網(wǎng) Python

這篇文章主要介紹了Python實(shí)現(xiàn)線程池代碼分享,本文直接給出實(shí)例代碼,需要的朋友可以參考下

原理:建立一個(gè)任務(wù)隊(duì)列,然多個(gè)線程都從這個(gè)任務(wù)隊(duì)列中取出任務(wù)然后執(zhí)行,當(dāng)然任務(wù)隊(duì)列要加鎖,詳細(xì)請(qǐng)看代碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import threading
import time
import signal
import os
 
class task_info(object):
  def __init__(self):
    self.func = None
    self.parm0 = None
    self.parm1 = None
    self.parm2 = None
   
class task_list(object):
  def __init__(self):
    self.tl = []
    self.mutex = threading.Lock()
    self.sem = threading.Semaphore(0)
   
  def append(self, ti):
    self.mutex.acquire()
    self.tl.append(ti)
    self.mutex.release()
    self.sem.release()
   
  def fetch(self):
    self.sem.acquire()
    self.mutex.acquire()
    ti = self.tl.pop(0)   
    self.mutex.release()
    return ti
   
class thrd(threading.Thread):
  def __init__(self, tl):
    threading.Thread.__init__(self)
    self.tl = tl
   
  def run(self):
    while True:
      tsk = self.tl.fetch()
      tsk.func(tsk.parm0, tsk.parm1, tsk.parm2) 
 
class thrd_pool(object):
  def __init__(self, thd_count, tl):
    self.thds = []
     
    for i in range(thd_count):
      self.thds.append(thrd(tl))
   
  def run(self):
    for thd in self.thds:
      thd.start()
       
       
def func(parm0=None, parm1=None, parm2=None):
  print 'count:%s, thrd_name:%s'%(str(parm0), threading.currentThread().getName())
   
def cleanup(signo, stkframe):
  print ('Oops! Got signal %s', signo)
   
  os._exit(0)
   
if __name__ == '__main__':
   
  signal.signal(signal.SIGINT, cleanup)
  signal.signal(signal.SIGQUIT, cleanup)
  signal.signal(signal.SIGTERM, cleanup)
   
  tl = task_list()
  tp = thrd_pool(6, tl)
  tp.run()
   
  count = 0
  while True:
     
    ti = task_info()
    ti.parm0 = count
    ti.func = func
    tl.append(ti)
    count += 1
     
    time.sleep(2)
  pass

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 亚洲男人网 | 精品国产仑片一区二区三区 | 国产精品久久久久久久久久久久久 | 成人国产精品视频 | 韩国久久 | 精精国产xxxx视频在线观看 | 亚洲视频在线免费观看 | 一区二区三区在线观看国产 | 99久久综合精品五月天 | 在线一级片 | 亚洲欧美激情精品一区二区 | 欧美日韩亚洲一区二区 | 一本一道久久久a久久久精品91 | 久久精品亚洲一区 | 国产成人一区二区三区 | 成人在线午夜 | 国产综合久久久 | 精品视频免费观看 | 日日夜夜精品免费视频 | 亚洲欧美另类久久久精品2019 | 五月婷婷综合网 | 69久久夜色精品国产69乱www | 欧美日本国产一区 | 欧洲精品在线视频 | 久久久久网站 | 久久久久久久久久亚洲 | 欧美精品乱码久久久久久按摩 | 久久99精品久久久久久园产越南 | 二区视频 | 中文字幕在线免费 | 亚洲日本乱码一区两区在线观看 | 福利成人 | 久久久九九 | 欧美透逼| 精品久久av | 国产毛片18片毛一级特黄日韩a | 99精品一区二区 | 国产欧美综合一区二区三区 | 国产高清在线精品一区二区三区 | 午夜国产在线 | 精品一区二区三区久久 |