The goal of my code is to place it into two EC2 instances which is then connected to a load balancer to distribute requests between the two instances.
This is my code which I am first trying to test in my local before I test it in the EC2 instances and then ultimately test everything with the load balancer as well.
from flask import Flask,request,session
##global s
s = 0
app = Flask(__name__)
@app.route("/", methods=["GET","POST"])
def disp():
if request.method == "GET":
global s
s = 0
return str(s)
if request.method == "POST":
global s
s = request.json["num"]
return str(s)
if __name__ =="__main__":
app.run()
##app.run('0.0.0.0', port=80)
The error that returns when I run locally is SyntaxError: Name 's' is used prior to global declaration. I tried removing the s=0 after the import line but the error still persists.
global s
means you want to overwrite contents of the global var.s
is only global per process. Usually, you run an application with multiple processes per server, so even with only one EC2 instance, you will receive different/unpredictable values fors
.