上一页 1 2 3 4 5 6 7 ··· 13 下一页

2019年9月15日

守护进程

摘要: '''主进程创建子进程,然后将该进程设置成守护自己的进程,守护进程就好比崇祯皇帝身边的老太监,崇祯皇帝已死老太监就跟着殉葬了。关于守护进程需要强调两点:其一:守护进程会在主进程代码执行结束后就终止其二:守护进程内无法再开启子进程,否则抛出异常:AssertionError: daemonic pro 阅读全文

posted @ 2019-09-15 10:36 别离 阅读(168) 评论(0) 推荐(0) 编辑

2019年9月14日

队列的使用

摘要: from multiprocessing import Queueq = Queue(3)q.put('hello') #‘put’就是放入q.put({'a':1})q.put([1,2,3])#队列中如果指定放入3个元素,则过多放入会卡在原地。直至有人取出n个元素,才能放入n个元素。原理同互斥锁 阅读全文

posted @ 2019-09-14 20:50 别离 阅读(109) 评论(0) 推荐(0) 编辑

互斥锁和join的区别

摘要: from multiprocessing import Processimport time, jsondef serch(name): dic = json.load(open('db.txt', 'r', encoding='utf-8')) print('%s查看到的票数为:%s'%(name 阅读全文

posted @ 2019-09-14 20:35 别离 阅读(226) 评论(0) 推荐(0) 编辑

互斥锁之模拟抢票

摘要: import time, jsonfrom multiprocessing import Process, Lock # 互斥锁def serch(name): time.sleep(1) dic = json.load(open('db.txt', 'r', encoding='utf-8')) 阅读全文

posted @ 2019-09-14 13:16 别离 阅读(170) 评论(0) 推荐(0) 编辑

互斥锁

摘要: from multiprocessing import Process, Lockimport timedef task(name, mutex): mutex.acquire() print('%s 1'%name) time.sleep(1) print('%s 2'%name) time.sl 阅读全文

posted @ 2019-09-14 13:15 别离 阅读(90) 评论(0) 推荐(0) 编辑

2019年9月12日

process对象的其他属性或者方法

摘要: #join方法import time, osfrom multiprocessing import Processdef task(name, n): print('%s is running'%name) time.sleep(n)if __name__ =='__main__': start = 阅读全文

posted @ 2019-09-12 21:36 别离 阅读(563) 评论(0) 推荐(0) 编辑

查看进程id的方法

摘要: from multiprocessing import Processimport timeimport osdef run(): print('%s is runing,parent is <%s>'%(os.getpid(), os.getppid())) time.sleep(3) print 阅读全文

posted @ 2019-09-12 20:38 别离 阅读(617) 评论(0) 推荐(0) 编辑

2019年9月10日

开启子进程的两种方式

摘要: # 方式一# from multiprocessing import Process# import time# def task(name):# print('%s is runing'%name)# time.sleep(3)# print('%s is down'%name)# if __na 阅读全文

posted @ 2019-09-10 14:38 别离 阅读(96) 评论(0) 推荐(0) 编辑

2019年9月7日

解决粘包问题终极版

摘要: 服务端: 阅读全文

posted @ 2019-09-07 12:36 别离 阅读(135) 评论(0) 推荐(0) 编辑

2019年8月26日

解决粘包问题简单版本

摘要: 服务端: 阅读全文

posted @ 2019-08-26 16:42 别离 阅读(122) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 ··· 13 下一页

导航