I'm just a beginner. I have a custom Package Module, so for now every time users request to the Server It takes like 30 seconds to initialize(load data for the Class) and then do the actual work.
Is there any so I can only initialize only one Instance of this Module and using for all requests from users?
I tried to follow a few ways but no hope
Thanks in advance,
By the way, I deployed it on Ec2 with Nginx Gunicorn.
Django - execute code at start-up.
Django: Run a script right after runserver
Asked
Active
Viewed 397 times
0

Tri nguyen minh
- 119
- 1
- 7
-
Yes and no. Python web applications typically utilize multiple Python processes and your instance should be initialised in all of them. To complicate things even more, WSGI servers can kill and then respawn processes dynamically (for example when using the `harakiri` or `cheaper` options in uWSGI -- no idea what would be the counterpart in gunicorn). Your best bet could be to serialize your class to an in-memory cache such as redis. Not much can be said without actually seeing your use case. – Selcuk Jun 07 '21 at 00:24
-
I see, Thank you for these bro. – Tri nguyen minh Jun 07 '21 at 00:32