I’m new to python so please excuse me if question doesn’t make sense in advance.
We have a python messaging server which has one file server.py with main function in it. It also has a class “*server” and main defines a global instance of this class, “the_server”. All other functions in same file or diff modules (in same dir) import this instance as “from main import the_server”.
Now, my job is to devise a mechanism which allows us to get latest message status (number of messages etc.) from the aforementioned messaging server.
This is the dir structure:
src/ -> all .py files only one file has main
In the same directory I created another status server with main function listening for connections on a different port and I’m hoping that every time a client asks me for message status I can invoke function(s) on my messaging server which returns the expected numbers.
How can I import the global instance, “the_server” in my status server or rather is it the right way to go?
You should probably use a single server and design a protocol that supports several kinds of messages. ‘send’ messages get sent, ‘recv’ message read any existing message, ‘status’ messages get the server status, ‘stop’ messages shut it down, etc.
You might look at existing protocols such as REST, for ideas.