I am using flask framework. The web page accepts few inputs like the file and and file name and when they click on submit, I ll basically run a shell script by passing those arguments. Currently, I am using subprocess to call the script which would run a docker container. I have no problem when I make one request at a time. The issue is when I make concurrent requests to server. Only one request is fulfilled and other request fails. Only when the script has successfully run I would redirect to other page where the use would be able to download the output file.
I am a newbie to flask and python, I appreciate your help. Thanks in Advance
def run_script(file_name,available_port):
print("Running the shell script")
script_output = subprocess.call(['./runDockerFlow.sh',file_name,available_port],cwd="/home/ubuntu-testing/Desktop/DockerWeb/")
print(script_output.stdout)
@app.route('/upload',methods=['POST','GET'])
def on_click_upload():
if request.method == 'POST':
f=request.files['file']
fname=request.form.get("FName")
f.save(os.path.join(app.config['UPLOAD_FOLDER'],secure_filename(f.filename)))
if available_port != 0:
run_script(f.filename,str(available_port))
return render_template("download.html",k=k)
@app.route('/download',methods=['GET','POST'])
def download():
return send_file("container_"+user_info.username+"/output_files.zip",as_attachment=True)
By the way I have configured the upload folder only adding necessary code for your reference.