首页 > 编程语言 > 详细

python--多线程的应用

时间:2020-02-13 15:03:07      阅读:67      评论:0      收藏:0      [点我收藏+]

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--多线程的应用

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!