HW4_first_com
This commit is contained in:
parent
39a3e8913f
commit
7ec82f80d1
@ -1,5 +1,7 @@
|
||||
import cmd
|
||||
import threading
|
||||
from threading import Thread
|
||||
from threading import Event
|
||||
|
||||
from queue import Queue
|
||||
|
||||
@ -7,11 +9,26 @@ from equipment.turtle_device import TurtleDevice
|
||||
|
||||
|
||||
class TurtleDeviceThread(threading.Thread):
|
||||
# TODO(Homework 4)
|
||||
|
||||
# TODO(Homework 4) \begin
|
||||
def __message_processing__(self):
|
||||
while True:
|
||||
new_message = self.queue.get()
|
||||
print("Name and args of action are {}".format(new_message))
|
||||
#self.device.
|
||||
self.queue.task_done()
|
||||
if self.event.is_set():
|
||||
break
|
||||
def __message_thread__(self):
|
||||
thread = Thread(target = __message_processing__, daemon=True)
|
||||
thread.start()
|
||||
# TODO(Homework 4) \end
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.device = TurtleDevice()
|
||||
self.queue = Queue()
|
||||
self.event = Event()
|
||||
|
||||
|
||||
class NoBlockingTurtleShell(cmd.Cmd):
|
||||
@ -20,13 +37,20 @@ class NoBlockingTurtleShell(cmd.Cmd):
|
||||
file = None
|
||||
|
||||
def __init__(self, turtle_thread: TurtleDeviceThread):
|
||||
pass # TODO(Homework 4)
|
||||
# TODO(Homework 4) \begin
|
||||
turtle_thread.__message_thread__()
|
||||
# TODO(Homework 4) \end
|
||||
|
||||
def do_execute(self, arg):
|
||||
pass # TODO(Homework 4)
|
||||
# TODO(Homework 4) \begin
|
||||
turtle_thread.queue.put(arg)
|
||||
# TODO(Homework 4) \end
|
||||
|
||||
def do_exit(self, arg):
|
||||
pass # TODO(Homework 4)
|
||||
# TODO(Homework 4) \begin
|
||||
turtle_thread.event.set()
|
||||
# TODO(Homework 4) \end
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user