KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The hello world demo for Flask is: from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run() What if I modified this like so: from flask import Flask app = Flask(__name__) a = 1 b = 2 c = 3 @app.route("/") def hello(): a += 1 b += a c += b return "Hello World!" if __name__ == "__main__": app.run() I understand WSGI application might have multiple threads. The hello function could be running on multiple threads at the same time, and then we'd have a race condition. Is this correct? If the above code is not thread safe, what can I do to make it thread safe? Avoiding globals is a possible solution, but can you always avoid globals? What if I want something like a python object cache?
Tags (comma-separated)
Save Edits
Cancel