When I am using multiprocessing module to establish a socket connection between a flask server and a client, the flask server fails to load the pages (routes).
Here is a minimal reproducible code:
Client.py
from multiprocessing.connection import Listener
port_number = 9000
listener = Listener(('localhost', port_number), authkey=b'secret password') ------------------
conn = listener.accept() ------------------
print("connection accepted form flask server") ------------------
while True:
msg = conn.recv()
print(msg)
Server.py
from multiprocessing.connection import Client
from flask import Flask
port_number = 9000
conn = Client(('localhost', port_number), authkey=b'secret password')
print("connection established with client")
conn.send("first message")
app = Flask(__name__)
@app.route("/")
def welcome():
return "hello world"
if __name__ == '__main__':
app.run(debug=True)
In the above codes, if client.py is run and then server.py is run, then the flask app's home page does not return "hello world".
But when the 3 marked lines are commented in the client.py file, i.e., when the sockets are not used for connection, then the above-mentioned issue does not occur.
In the above-mentioned codes, if the socket connection from the server.py is made with any other files, then also the flask app does not work.
What could be the reason for this?? I am unable to find some obvious logical reason for this.