码迷,mamicode.com
首页 > 编程语言 > 详细

python--多线程的应用

时间:2020-02-13 14:58:23      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:splay   port   应用   onclick   lob   lis   imp   调用   release   

python 多线程执行函数,以及调用函数时传参

技术图片
import threading

def func1():
    print(this is function1)


def func2(x,y):
    print(this is function2)
    print(x+y)

threads = []
threads.append(threading.Thread(target=func1))
threads.append(threading.Thread(target=func2,args=(11,22,)))
print(threads)
if __name__ == __main__:
    for t in threads:
        print(t)
        t.start()
View Code

 

  

python 多线程执行cmd终端命令(os.system),

技术图片
# import threading
# import time
# class ThreadImpl(threading.Thread):
#     def __init__(self, num,cmds):
#         threading.Thread.__init__(self)
#         self._num = num
#         self._cmds = cmds
#
#     def run(self):
#         global total, mutex
#
#         # 打印线程名
#
#         print(threading.currentThread().getName())
#         os.system(self._cmds)
#         for x in range(0, int(self._num)):
#             # 取得锁
#             mutex.acquire()
#             # total = total + 1
#             # 释放锁
#             mutex.release()
#
#
# if __name__ == ‘__main__‘:
#     starttime = time.time()
#     global  mutex
#     mutex = threading.Lock()
#     threads = []
#     for x in range(len(cmdList)):
#         threads.append(ThreadImpl(100,cmdList[x]))
#     # 启动线程
#     for t in threads:
#         t.start()
#     # 等待子线程结束
#     for t in threads:
#         t.join()
#
#     totaltime = time.time() - starttime
#     # print(‘========‘)
#     # print(totaltime)
View Code

 

  

 

python--多线程的应用

标签:splay   port   应用   onclick   lob   lis   imp   调用   release   

原文地址:https://www.cnblogs.com/lutt/p/12303405.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!