Update test_mutiproser.py

This commit is contained in:
沈瑗杰 2021-01-11 23:13:50 +08:00
parent 3626d448ec
commit ada9980420

View File

@ -1,41 +1,81 @@
import multiprocessing as mp
import os, time
from multiprocessing.context import Process
import os, time, random
class Main():
class Main(mp.Process):
def __init__(self, dev) -> None:
Process.__init__(self)
self.aaa = 1
self.ttt = False
self.ttt = True
self.dev = dev
def main(self):
def run(self):
while self.ttt:
print(time.time())
print(os.getpid())
time.sleep(0.5)
time.sleep(3)
while not(self.dev.using):
self.dev.using = True
print("开始调用a")
if self.dev.dev1 != 0:
self.aaa = self.dev.dev1
if self.dev.bget == True:
print("B 没拿到")
else:
print("B 拿到了")
self.dev.bget = False
self.dev.aget = True
self.ttt = self.dev.a
self.dev.using = False
print("结束调用a")
break
print(" aaa = ", self.aaa)
print("完事,收工---a")
class render():
class render(mp.Process):
def __init__(self, dev) -> None:
self.bbb = 3
Process.__init__(self)
self.ggg = True
self.dev = dev
def run(self):
while self.ggg:
print(os.getpid())
time.sleep(3)
while not(self.dev.using):
self.dev.using = True
if random.choice(range(0, 5, 1)) == 4:
self.dev.dev1 = self.bbb
print("开始调用b")
if self.dev.aget == True:
print("A 没拿到")
else:
print("A 拿到了")
self.dev.aget = False
self.dev.bget = True
self.ggg = self.dev.b
self.dev.using = False
print("结束调用b")
break
print("完事,收工---b")
class Delivery():
def __init__(self) -> None:
self.using = False
self.dev1 = ""
self.dev1 = 0
self.a = True
self.b = True
self.aget = False
self.bget = False
if __name__ == "__main__":
dev = Delivery()
A = Main(dev)
B = render(dev)
print(":aaa")
A.start()
B.start()
time.sleep(5)