Closed TheWiseC0der closed 6 months ago
Hi! Thanks for raising the issue. Will work on fixing it tomorrow or the other day
Hi! I have spent some time working to address this issue by implementing a Singleton pattern via Metaclasses. Despite this, the problem persisted. After conducting numerous tests, I realized that the recurring model loading issue in the development environment occurs because Django reloads the app soon after its creation. Therefore, even the solution you suggested was not ineffective. Running the server with the --noreload
option confirmed that the app is indeed reloaded, which results in the model being loaded a twice despite using a singleton pattern
currently get two instances. when loading my app it loads the model twice at startup. can you guys not use a metaclass for it instead? never get problems with that way of singleton pattern.
"""metaclass for the Singleton pattern metaclasses are used for class creation, they are like classes for classes, their logic specifies how the class should behave, not the instances of the class""" class SingletonMeta(type): """ The Singleton class can be implemented in different ways in Python. Some possible methods include: base class, decorator, metaclass. We will use the metaclass because it is best suited for this purpose. """
We'll store instances of the Singleton classes here.