I have a Main process that is serving a Flask application and a Subprocess created with Multiprocess that has a concurrent task. When the Subprocess terminates I want the main Process to also terminate but this does not happen because the main process never reaches the join statement due to the flask serving. In this example I also use socketio, but it is basically the same as flask.
This is only a simplified version of the code:
def listener(video_trigger, sensor_lock):
    try:     
        # connecting to hardware
    except Exception as e:  
        print(f"Hardware not connected: {str(e)}")
        sys.exit()
    while True:
        # read out hardware
if __name__ == "__main__":
    p = Process(target=listener, args=())
    p.start() 
    socketio.run(app, host='0.0.0.0', port=81)
    p.join()
 
    