I’m trying to call a function in a file from another file. I have a file named client.py. In that file there is a function named reset(), which resets the client. I have another file controller.py, I want to call client.reset() from controller, such that it resets the client, i.e. should run within client, not controller.
Is there any way of doing this?
EDIT:
controller.py and client.py are running as separate processes. import method imports function from another module into the scope of file in which it is being imported. This is not what I want. I want a method by which controller.py can make client.py invoke reset() on itself.
While some have suggested communicating with your processes via the subprocess PIPE, the issue still remains that your client.py process would need to be expecting and listening for data on stdin to give it an action to perform. It isn’t clear what your client is doing, but maybe it really is just sitting in a loop reading from stdin.
@mfrankli has given a general link to python IPC in his answer. But to be more specific, you need some type of listening implementation in your client.py for the controller to send messages to. Here are some various approaches:
If you are interested in the ZeroMQ route, I actually have a simple project that creates an RPC setup using it: https://github.com/justinfx/pyRpc