Code in module_a:
varA=10
class ClassX:
def fn1():
return varA
Code in Flask_api:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
import module_a # or from module_a import varA
module_a.varA += 1 # or varA+=1
return module_a.varA
When running on development server, there maybe 1 process and 1 thread handling all request. However, on production, since each flask endpoint invocation can spin up in a new process or a new thread, then, I am curious to know if there are any things I need to be careful about?
For example: It is not process safe and thread safe.
Also is there difference between doing imports in function vs outside.