摘要:
#_author:来童星#date:2019/12/17#生产者消费者模式-->线程from queue import Queueimport random,time,threading#生产者class Producer(threading.Thread): def __init__(self,n 阅读全文
摘要:
#_author:来童星#date:2019/12/17#互斥锁from threading import Thread,Lockimport timen=100def func(): global n mutex.acquire() temp=n time.sleep(0.1) n=temp-1 阅读全文
摘要:
#_author:来童星#date:2019/12/17from threading import Threadimport timedef plus(): print('子线程1开始') global num num+=50 print('num is %d'%num) print('子线程1结束 阅读全文
摘要:
#_author:来童星#date:2019/12/17#使用Thread创建线程import threadingimport timeclass Sunthread(threading.Thread): def run(self): for i in range(3): time.sleep(1) 阅读全文
摘要:
#_author:来童星#date:2019/12/17#使用threading模块创建线程import threading,timedef process(): for i in range(3): time.sleep(1) print('thread name is %s'%threading 阅读全文
摘要:
#_author:来童星#date:2019/12/17#使用队列在进程间通信from multiprocessing import Process,Queueimport time#向队列中写入数据def write_task(q):# 一定要将q传进去 if not q.full(): for 阅读全文
摘要:
#_author:来童星#date:2019/12/17#多进程队列的使用from multiprocessing import Queueif __name__=='__main__': q=Queue(3)# 初始化一个Queue对象,最多可接收3条put消息 q.put('消息1') q.pu 阅读全文
摘要:
#_author:来童星#date:2019/12/17#通过队列实现进程间通信from multiprocessing import Processdef plus(): print(' 子进程1开始 ') global g_num g_num+=50 print('g_num is %d'%g_ 阅读全文
摘要:
#_author:来童星#date:2019/12/17#通过队列实现进程间的通信from multiprocessing import Poolimport osimport timedef func(name): print('子进程(%s)执行func %s...'%(os.getpid(), 阅读全文
摘要:
#_author:来童星#date:2019/12/17#通过队列实现进程间的通信from multiprocessing import Poolimport osimport timedef func(name): print('子进程(%s)执行func %s...'%(os.getpid(), 阅读全文
摘要:
#_author:来童星#date:2019/12/17from multiprocessing import Processimport timeimport os#两个子进程将会调用的两个方法def child_1(i): print('子进程(%s)开始执行,父进程为(%s)'%(os.get 阅读全文
摘要:
#_author:来童星#date:2019/12/17# 使用Process子类创建进程from multiprocessing import Processimport timeimport os#继承Process类class SubProcess(Process): #由于Process类本 阅读全文