This commit is contained in:
沈瑗杰 2021-01-16 22:21:41 +08:00
parent 9a0737d906
commit 431816ff68

View File

@ -2,8 +2,10 @@
import threading import threading
import time import time
import os import os
import sys
import random import random
class Aclass(threading.Thread): class Aclass(threading.Thread):
def __init__(self, dev, ID): def __init__(self, dev, ID):
threading.Thread.__init__(self) threading.Thread.__init__(self)
@ -23,12 +25,17 @@ class Aclass(threading.Thread):
print(self.id, os.getpid(), os.getppid(), self.running) print(self.id, os.getpid(), os.getppid(), self.running)
time.sleep(1) time.sleep(1)
def stop(self):
sys.exit()
class dev(): class dev():
def __init__(self): def __init__(self):
self.using = False self.using = False
self.gets = {'a': False, 'b': False} self.gets = {'a': False, 'b': False}
self.running = {'a': True, 'b': True} self.running = {'a': True, 'b': True}
Dev = dev() Dev = dev()
A = Aclass(Dev, 'a') A = Aclass(Dev, 'a')
time.sleep(random.random()) time.sleep(random.random())
@ -36,7 +43,8 @@ B = Aclass(Dev, 'b')
A.start() A.start()
B.start() B.start()
print("hmmm") print("hmmm")
while True: try:
while True:
In = input() In = input()
if In == "stop": if In == "stop":
Dev.running['a'] = False Dev.running['a'] = False
@ -46,3 +54,6 @@ while True:
eval(In) eval(In)
except: except:
print(EnvironmentError) print(EnvironmentError)
except KeyboardInterrupt:
A.stop()
B.stop()