JS Python Communication - nodesign/weio GitHub Wiki

JS - Python Communication

  1. User Tornado main handler WeioHandler() is called every time something comes over /api route https://github.com/nodesign/weio/blob/next/weioRunner.py#L415

  2. This handler liver in ./handlers/weioJSPYHandler.py, and it is just parsing the RPC and putting it in queue

  3. When PLAY is pressed, separate thread called launcher is started (https://github.com/nodesign/weio/blob/next/weioRunner.py#L168), and it starts all other user processes and then loops in while True, reading this queue to get info from weioJSPYHandler.py

  4. When it gets this info, it executed the function directly in Python (for example digitalWrite()): https://github.com/nodesign/weio/blob/next/weioRunner.py#L285

  5. Result is put in the other queue, because there is one more thread dedicated to send everything back to JS

  6. This thread gets result from this other queue here: https://github.com/nodesign/weio/blob/next/weioRunner.py#L312 and shoots it back to WebSocket connection