上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 25 下一页
摘要: 1.数据共享 实现进程之间的数据共享 from multiprocessing import Manager,Process class MyPro(Process): def __init__(self,dic): super().__init__() self.dic = dic def run 阅读全文
posted @ 2019-12-22 19:11 手可摘星辰。 阅读(314) 评论(0) 推荐(0) 编辑
摘要: 1.管道 from multiprocessing import Pipe conn1,conn2 = Pipe() #返回两个值 conn1.send('wdc') #发送 print(conn2.recv()) #接收 conn2.send('yhf') print(conn1.recv()) 阅读全文
posted @ 2019-12-22 14:42 手可摘星辰。 阅读(350) 评论(0) 推荐(0) 编辑
摘要: 消费者和生产者模型 from multiprocessing import Process,Queue import time import random class Producer(Process): def __init__(self,name,food,q): super().__init_ 阅读全文
posted @ 2019-12-21 20:45 手可摘星辰。 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 1.队列 from multiprocessing import Queue q = Queue(5) #创建队列对象,队列大小为5,队列中只能存放5个元素 q.put(1) #往队列中添加元素 q.put(2) q.put(3) q.put(4) q.put(5) print(q.full()) 阅读全文
posted @ 2019-12-19 23:06 手可摘星辰。 阅读(279) 评论(0) 推荐(0) 编辑
摘要: 1.事件 :通过一个信号来控制多个进程同时执行或者阻塞。 一个信号可以使所有的进程都进入阻塞状态,也可以控制所有的进程接触阻塞,一个事件被创建之后,默认是阻塞状态。 from multiprocessing import Event e = Event() #创建事件对象 print(e.is_se 阅读全文
posted @ 2019-12-16 19:19 手可摘星辰。 阅读(931) 评论(0) 推荐(0) 编辑
摘要: 多进程模拟买票~ import time import json from multiprocessing import Process class Show(Process): #查 def run(self): with open('ticket') as f: dic = json.load( 阅读全文
posted @ 2019-12-15 15:31 手可摘星辰。 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 1.守护进程 守护进程会随着主进程的代码执行结束而结束。 语法:进程对象.daemon = True时,表示将进程设置为守护进程,一定在start之前设置。 import time from multiprocessing import Process class MyProcess(Process 阅读全文
posted @ 2019-12-15 14:07 手可摘星辰。 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 1.多进程的第二种启动方式 import os from multiprocessing import Process # 创建一个自定义类,继承Process类 class MyProcess(Process): # 必须实现一个run方法,run方法中是子进程中执行的代码 def run(sel 阅读全文
posted @ 2019-12-14 19:39 手可摘星辰。 阅读(280) 评论(0) 推荐(0) 编辑
摘要: from multiprocessing import Process import os def func1(): print('子进程1',os.getpid()) #子进程:获取当前进程的进程号 print('子进程的父进程:', os.getppid()) #获取进程的父进程id def f 阅读全文
posted @ 2019-12-12 22:17 手可摘星辰。 阅读(203) 评论(0) 推荐(0) 编辑
摘要: # 给动态生产的类定义一个方法 def __init__(self,name): self.name = name print(self.name) def take(self,obj): print(obj) # 动态生成一个类type('类名',(父类1,父类2,),{字典:属性或方法}) Do 阅读全文
posted @ 2019-12-10 22:46 手可摘星辰。 阅读(159) 评论(0) 推荐(0) 编辑
上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 25 下一页