I would use a socket connection. Essentially, you are writing a very simple server that only accepts one connection at a time.
import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("localhost", 9988)) s.listen(1) while True: conn, addr = s.accept() data = conn.recv(1024) conn.close() my_function_that_handles_data(data)
s.accept() is a blocking call. He is waiting for a connection. Then you read about the connection. In this case, we assume that the length of the parameters is only 1024 bytes. Then we do something with the data received from the socket and expect another connection.
A client might look like this:
import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("localhost", 9988)) s.sendall('My parameters that I want to share with the server') s.close()
The best part is that in the future, if the client and the server will no longer work on the same machine, then simply changing "localhost" to the actual IP address or domain name that you are about to hit.
source share