У нас есть работающий REST API, который обрабатывает множество конечных точек различий для FrontEnd. В течение одной указанной c конечной точки, где команда подпроцесса должна обработать операцию, все остальные конечные точки останавливаются и ждут, пока подпроцесс завершит работу sh. Может ли кто-нибудь помочь мне понять, почему это происходит? Мои мысли о том, что Python Flask работает асинхронно?
[...]
class withdrawCrypto(Resource):
def get(self):
auth = json.loads('{"ERROR" : "User authentication failed!"}')
wrongAmount = json.loads('{"ERROR" : "Wrong amount"}')
wrongWlt = json.loads('{"ERROR" : "Invalid wallet provided. Please check the wallet addr!"}')
notEnough = json.loads('{"ERROR" : "You don\'t have enough crypto to withdraw this amount"}')
account = str(request.args.get('account'))
token = str(request.args.get('token'))
wallet = str(request.args.get('wlt'))
count = int(request.args.get('count'))
if len(wallet) != 34:
return jsonify(data=wrongWlt)
if wallet[0] != 'B':
return jsonify(data=wrongWlt)
cursorLG.execute("select balance from btc WHERE login=%s;", account)
checkBalance = cursorLG.fetchall()
if checkBalance[0]['balance'] < int(count):
return jsonify(data=notEnough)
cursorLG.execute("select cred from accounts WHERE login=%s;", account)
userCheck = cursorLG.fetchall()
if userCheck[0]['secret'] == token:
if count and int(count) > 0:
host = credentials['rpc']
user = credentials['rpcuser']
passwd= credentials['rpcpassword']
timeout = credentials['rpcclienttimeout']
command = 'bitcoin-cli -rpcconnect=' + host + ' -rpcuser=' + user + ' -rpcpassword=' + passwd + ' -rpcclienttimeout=' + timeout + ' sendtoaddress ' + wallet + ' ' + str(count)
result = subprocess.check_output(command,shell=True).strip()
cursorLG.execute("select balance from btc WHERE login=%s", account)
current = cursorLG.fetchall()
setNew = int(int(current[0]['balance']) - int(count))
cursorLG.execute("replace into btc (login, balance, lastwithdrawalwlt) values (%s, %s, %s) ", (account, setNew, wallet))
return jsonify(data=result.decode("utf-8"))
else:
return jsonify(data=wrongAmount)
else:
print('Failed Crypto withdrawal! Actual passw / user sent: ', userCheck[0]['secret'], token)
return jsonify(data=auth)
[...]
# Serve the high performance http server
if __name__ == '__main__':
http_server = WSGIServer(('', 9000), app)
http_server.serve_forever()
Все остальные конечные точки работают быстро без каких-либо задержек. Любая помощь приветствуется.