Socket.io server communicating with parent process. #1266
PapyrusNotes
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Introduction
Hi, I am posting this to share my experience on handling Python Socke.io.
This post would be useful to someone trying to open Socket.io based python socket on their web server.
Before getting down to business, here is what I learned from my failure.
What I learned from my failure
If you have socket in your frontend service, you need to synchronize format between frontend and backend.
Frontend might use other interface for streaming.
For example, if JS use socket.io,
you also need to use socket.io implementation for proper communication.
Otherwise, message will be interpreted in a way not you wanted and you cannot make proper logic in your backend.
( This is my first reason why I've gone all the way to here )
Think again when your backend application is using Python native Threads.
Adopting eventlet or greenlet is not easy job to integrate with existing logic which contains Python native Threads.
If you adopt this library and make server for serving Socket.io instance,
the program will not execute the sequence as you expected.
Thus, If you have to make logic using Python native Threads and Socket.io,
I strongly recommend to use multiprocess.
How?
Let child process forked by parent process ( main process ), and implement Sokcet.io network logics to child process.
Think of simple architecture of parent process is producer and child process is consumer. ( Also, sender )
Message between parent process and child process can be transported with multiprocessing queue.
And main thread of child process can initiate server ,
background thread of child process can watch the queue and emit the message to the client.
If you need repository, here is a link
Beta Was this translation helpful? Give feedback.
All reactions