摘要: 原因:并发运行,效率高,但竞争写同一文件,数据写入错乱加锁:购票行为由并发变成了串行,牺牲了运行效率,但保证了数据安全通过mutex.acquire()加锁,mutex.release()解锁也可通过with mutex实现自动加解锁注意:join只能将进程的任务整体变成串行代码:import js 阅读全文
posted @ 2018-09-05 16:44 没有显示名称 阅读(164) 评论(0) 推荐(0)
摘要: 开启子进程的方式一:导入Process模块,通过process类实例化出一个对象,调用run方法开启子进程from multiprocessing import Processimport timedef task(name): print('%s is running' %name) time.s 阅读全文
posted @ 2018-09-05 16:42 没有显示名称 阅读(167) 评论(0) 推荐(0)