Anders and Briegel in Python
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

30 行
860B

  1. """
  2. Allows us to visualize the state in a browser
  3. """
  4. import atexit, json, time
  5. from graphstate import GraphState
  6. from websocket import create_connection
  7. class VisibleGraphState(GraphState):
  8. """ Overloads the graph state with methods for sending to the browser over a websocket """
  9. def __init__(self, *args, **kwargs):
  10. """ Constructor """
  11. GraphState.__init__(self, *args, **kwargs)
  12. self.ws = create_connection("ws://localhost:5000")
  13. atexit.register(self.shutdown)
  14. def shutdown(self):
  15. """ The client should shut down automatically on close """
  16. self.update()
  17. self.ws.close()
  18. def update(self, delay = 0.5):
  19. """ Call this function when you are ready to send data to the browser """
  20. data = json.dumps(self.to_json())
  21. self.ws.send(data)
  22. time.sleep(delay)