print_terminal.py 632B

1234567891011121314151617181920212223242526272829
  1. # coding: utf-8
  2. import time
  3. import sys
  4. sys.path.append('../')
  5. from synergine2.terminals import Terminal, TerminalPackage, TerminalManager
  6. class PrintTerminal(Terminal):
  7. def receive(self, package: TerminalPackage):
  8. print(package.value)
  9. sys.stdout.flush()
  10. def run(self):
  11. while self.read():
  12. print('Hello world')
  13. sys.stdout.flush()
  14. time.sleep(1)
  15. terminals_manager = TerminalManager(terminals=[PrintTerminal()])
  16. terminals_manager.start()
  17. for i in range(3):
  18. time.sleep(2)
  19. terminals_manager.send(TerminalPackage('Just print me'))
  20. terminals_manager.stop()