I am running below python script which eventually runs shell script which gives me the list of running version in k8s namespace. Getting the result but it is taking time > 3sec. So, this is causing "operation_timeout" from slack. I am new to python, have gone with various docs regarding delay but that didn't help as those were very complex.
from subprocess import Popen, PIPE
from subprocess import check_output
from flask import Flask
def get_shell_script_output_using_communicate():
session = subprocess.Popen(['./version.sh'], stdout=PIPE, stderr=PIPE)
stdout, stderr = session.communicate()
if stderr:
raise Exception("Error "+str(stderr))
return stdout.decode('utf-8')
def get_shell_script_output_using_check_output():
stdout = check_output(['./version.sh']).decode('utf-8')
return stdout
app = Flask(__name__)
@app.route('/test',methods=['POST'])
def home():
return '`Version List` ```'+get_shell_script_output_using_check_output()+'```'
app.run(host='0.0.0.0', port=5002, debug=True)
Is there a way to get the response even if the command is taking more than 10sec? Thanks!