I'm developing a Flask web application on an Ubuntu 22.04.3 LTS server, where I need to run multiple instances of a Windows executable (main.exe) simultaneously. The application is deployed using Gunicorn with Eventlet.
The main.exe is located in the root directory of my Flask app. Each client's request triggers a subprocess in Flask to run this executable using Wine. I'm managing these subprocesses in a dictionary in Flask, keyed by unique client IDs, to ensure that each client interacts with their own instance of the executable.
import subprocess
# Dictionary to manage subprocesses for each client
client_processes = {}
# Flask route
@app.route('/run_simulation', methods=['POST'])
def run_simulation():
client_uid = # [code to retrieve client_uid]
args = [
"/usr/bin/wine",
"/home/myapp/main.exe",
# ... additional arguments ...
]
try:
# Start the subprocess and store it in the dictionary
simulation_process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
client_processes[client_uid] = simulation_process
# [rest of the code]
except Exception as e:
# [exception handling]
# [return response]
# [Rest of Flask app code]
The issue I'm facing is that when one client's subprocess is running and another client starts theirs, the first subprocess seems to be interrupted or stopped. I'm using Wine to run the Windows executable, and I'm wondering if this might be contributing to the issue.
Could this problem be related to how Wine handles multiple instances of the same executable? Are there any specific configurations or best practices in Wine, Ubuntu, or Flask (especially with Gunicorn and Eventlet) that I should consider to run multiple instances of a Windows executable without them interfering with each other?
Any insights or advice on this matter would be greatly appreciated.