# coding=utf-8
import threading
import time
import string
import random


class TestTreading(threading.Thread):
    def __init__(self,func):
        threading.Thread.__init__(self)
        self.func =func
    #@override
    def run(self):
        mutex = threading.Lock()
        mutexFlage = mutex.acquire()
        if mutexFlage:
            self.res=self.func()
            print(time.asctime())
        mutex.release()
        return self.res
    # def get_res(self):
    #     return  self.res
def add():
    return ''.join(random.sample(string.hexdigits,random.randint(16,18)))

def executors():
    resList=[]
    pool=[]
    for i in range(10000):
        th=TestTreading(add)
        pool.append(th)

    for t in pool:
        t.start()
    for t in pool:
        t.join()
        resList.append(t.run())
    return resList
if __name__ == '__main__':
    executors()

  

相关文章:

  • 2021-10-19
  • 2021-11-05
  • 2021-07-07
  • 2022-12-23
  • 2021-12-02
  • 2021-11-11
  • 2021-05-30
  • 2021-08-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案