From 9a0737d906c876d5c037642ad42e4d5d0d282005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E7=91=97=E6=9D=B0?= <3695888@qq.com> Date: Fri, 15 Jan 2021 21:22:34 +0800 Subject: [PATCH] reeeee --- .gitignore | 1 + test_mutiproser.py | 13 +++++++------ test_threading.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 test_threading.py diff --git a/.gitignore b/.gitignore index c69ae1b..09f9a02 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # VScode file .vscode/ +SR.code-workspace # PYCharm file .idea/ diff --git a/test_mutiproser.py b/test_mutiproser.py index 218b5b2..5ec03a5 100644 --- a/test_mutiproser.py +++ b/test_mutiproser.py @@ -16,13 +16,13 @@ class Main(mp.Process): def run(self): while self.ttt: print(os.getpid()) - time.sleep(1) + time.sleep(2) 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: + if self.dev.bget == False: print("B 没拿到") else: print("B 拿到了") @@ -46,18 +46,18 @@ class render(mp.Process): def run(self): while self.ggg: print(os.getpid()) - time.sleep(1) + time.sleep(2) 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: + if self.dev.aget == False: print("A 没拿到") else: print("A 拿到了") self.dev.aget = False - self.dev.bget = True + # self.dev.bget = True self.ggg = self.dev.b self.dev.using = False print("结束调用b") @@ -81,8 +81,9 @@ if __name__ == "__main__": B = render(dev) print(":aaa") A.start() + time.sleep(1) B.start() - time.sleep(3) + time.sleep(5) print("gogogogogogoogogogogo") dev.a = False print("A is deadddddddddddddddddddd AAAAAAAA") diff --git a/test_threading.py b/test_threading.py new file mode 100644 index 0000000..dbd69dc --- /dev/null +++ b/test_threading.py @@ -0,0 +1,48 @@ + +import threading +import time +import os +import random + +class Aclass(threading.Thread): + def __init__(self, dev, ID): + threading.Thread.__init__(self) + self.running = True + self.value = 0 + self.dev = dev + self.id = ID + print(self.id) + + def run(self): + while self.running: + while self.dev.using == True: + continue + self.dev.using = True + self.running = self.dev.running[self.id] + self.dev.using = False + print(self.id, os.getpid(), os.getppid(), self.running) + time.sleep(1) + +class dev(): + def __init__(self): + self.using = False + self.gets = {'a': False, 'b': False} + self.running = {'a': True, 'b': True} + +Dev = dev() +A = Aclass(Dev, 'a') +time.sleep(random.random()) +B = Aclass(Dev, 'b') +A.start() +B.start() +print("hmmm") +while True: + In = input() + if In == "stop": + Dev.running['a'] = False + Dev.running['b'] = False + break + try: + eval(In) + except: + print(EnvironmentError) \ No newline at end of file