摘要: from threading import Thread msg_l=[] format_l=[] def talk(): while True: msg=input('>>: ').strip() if not msg:continue msg_l.append(msg) def format_m 阅读全文
posted @ 2018-02-07 20:26 xiongrongqin123 阅读(119) 评论(0) 推荐(0) 编辑
摘要: #由并发变成了串行,牺牲了运行效率,但避免了竞争 from multiprocessing import Process,Lock import os,time def work(lock): lock.acquire() print('%s is running' %os.getpid()) ti 阅读全文
posted @ 2018-02-07 20:17 xiongrongqin123 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 其一:守护进程会在主进程代码执行结束后就终止 其二:守护进程内无法再开启子进程,否则抛出异常:AssertionError: daemonic processes are not allowed to have children 注意:进程之间是互相独立的,主进程代码运行结束,守护进程随即终止 阅读全文
posted @ 2018-02-07 20:12 xiongrongqin123 阅读(102) 评论(0) 推荐(0) 编辑
摘要: from multiprocessing import Process import time import random class Piao(Process): def __init__(self,name): self.name=name super().__init__() def run( 阅读全文
posted @ 2018-02-07 20:11 xiongrongqin123 阅读(91) 评论(0) 推荐(0) 编辑
摘要: #开进程的方法二: import time import random from multiprocessing import Process class Piao(Process): def __init__(self,name): super().__init__() self.name=nam 阅读全文
posted @ 2018-02-07 20:10 xiongrongqin123 阅读(95) 评论(0) 推荐(0) 编辑
摘要: #开进程的方法一: import time import random from multiprocessing import Process def piao(name): print('%s piaoing' %name) time.sleep(random.randrange(1,5)) pr 阅读全文
posted @ 2018-02-07 20:09 xiongrongqin123 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-01-31 20:57 xiongrongqin123 阅读(424) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-01-31 20:53 xiongrongqin123 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-01-31 20:53 xiongrongqin123 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 对象是特征与技能的结合体,类就是一系列对象相似的特征与技能的结合体在现实世界中:一定是先有的一个个具体存在的对象,后总结出的类在程序中:一定保证先定义类,后产生对象 # 类体代码在类的定义阶段就会立刻执行,class Student: school='oldboy' def learn(self): 阅读全文
posted @ 2018-01-16 20:44 xiongrongqin123 阅读(128) 评论(0) 推荐(0) 编辑