I’m currently working to send image data, in the form the byte arrays, from Python to JavaScript. I tried to use Redis as a means of in-memory, persistent communication channel, but it seems like bad design to force users to separately run redis-cli
in the terminal. I tried to see if I can launch a Redis server using Python, but I could not find anything for that either. Is there an efficient, user-friendly way of setting up this type of communication? Would socket programming be a good way of setting up this communication channel as well?
2
Answers
To answer my own question, I decided to go down the path of using websockets to achieve bidirectional communication between Python and JavaScript. Specifically, I set up a websocket using tornado, setup Python and JavaScript cilents, and communicate via event-driven programming.
I really wanted to steer away from calling
redis-cli
or any other bash commands via subprocess, and I think using websockets is an elegant and efficient solution.You can start redis-cli from your python code using subprocess. As per my understanding of your problem, you have to use subprocess.Popen(), to run a terminal command in a separate thread(in parallel). If want your python code to wait for the terminal command to finish, you can use subprocess.call()