随笔分类 -  python-多线程&进程

线程锁lock&rlock
摘要:首先关于锁: 1 使用锁会影响性能 2 锁可能谁导致死锁 比如: 线程A acquire a 等待b 线程B acquire b 等待a 这种资源竞争就会导致死锁 【Lock】 lock 不能连续获取两次(死锁了), 因为第二个锁会一直等待第一个释放 【Rlock】 可重入锁 Rlock 在同一个线 阅读全文

posted @ 2021-01-02 20:56 思此狂 阅读(292) 评论(0) 推荐(0) 编辑

threading.local
摘要:import threading import time def music(a,b): fo = open("test.txt1", "w") fo.write(a+b) fo.close() def move(c,d): fo = open("test.txt2", "w") fo.write( 阅读全文

posted @ 2021-01-02 20:37 思此狂 阅读(91) 评论(0) 推荐(0) 编辑

threading Event
摘要:通过threading.Event()可以创建一个事件管理标志,该标志(event)默认为False,event对象主要有四种方法可以调用: event.wait(timeout=None):调用该方法的线程会被阻塞,如果设置了timeout参数,超时后,线程会停止阻塞继续执行; event.set 阅读全文

posted @ 2020-12-19 22:48 思此狂 阅读(592) 评论(0) 推荐(0) 编辑

python multiprocessing
摘要:from multiprocessing import Process import os # 子进程要执行的代码 def run_proc(name): print('Run child process %s (%s)...' % (name, os.getpid())) if __name__= 阅读全文

posted @ 2020-09-15 17:38 思此狂 阅读(293) 评论(0) 推荐(0) 编辑

python 队列Queue
摘要:from Queue import Queue qlist=Queue(maxsize=300) import threading for i in range(20): qlist.put("hello num%d" %(i)) def process_work(qlist): while Tru 阅读全文

posted @ 2020-05-27 23:45 思此狂 阅读(191) 评论(0) 推荐(0) 编辑

python-subprocess
摘要:【subprocess 模块】 subprocess 允许你生成新的子进程,连接到子进程的标准输入,输出,错误输出等,并获得它的返回值,这个模块后续会替换掉一些老的模块 os.systemos.spawn*os.popen*popen2.*commands.* subprocess.call():运 阅读全文

posted @ 2017-12-23 17:08 思此狂 阅读(224) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
点击右上角即可分享
微信分享提示