Pregunta

I am a beginner in django and was doing a test here to access to a model in infinite loop. But while running the following code I found the memory is filled up quickly and end up with a memory leaking error.

Could anybody tell me what is the safe/simple way to access to model in a infinite loop? Should I use threading in this kind of program?

from patient_post.models import Patient
def messageScheduler():
    while 1:
    patients = Patient.objects.all()
    del patients
¿Fue útil?

Solución

You should use a job scheduler for such thing, you have multiple options with different features and complexity and your choice will depend on your requirements. Here is some examples:

django-chronograph

Celery

django-rq

Another option is to create management task and run it using a cron job.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top