In my flask application, I have to instantiate an object (no parameters are used in its instantiation), and it takes around 10 seconds to create (let's call the resulting object 'my_obj'). After a user fill out a text box in my website, I call 'my_obj.create(text)' and I pass in the text from the input, and this line returns a string as an output (calling the 'create' method doesn't change anything about 'my_obj'). Since I don't want to repeatedly instantiate the 'my_obj' object due to the long wait time, I was considering instantiating the 'my_obj' in a separate .py file and create a shallow copy of 'my_obj' within the view function. However, I don't exactly know the mechanics of how Flask uses shallow-copied objects in the context of multiple simultaneous users. Is it safe for me to use shallow copies of 'my_obj' inside a view function (that has many simultaneous users)?
Asked
Active
Viewed 16 times
0
-
1Please kindly share your code as code snippet to clarify your issue. – Muhtar Jul 09 '21 at 21:15