Skip to content
Advertisement

Local Django server unresponsive when adding function scheduling

I am trying to schedule a function to run everyday using the Schedule library.

My local Django server however hangs and becomes unresponsive during the system check after saving the schedules to my code. It is only when I remove the schedule code the system check passes and the server runs without problem.

I have copied the example directly from the documentation and the server is not returning any errors so I am unsure what the problem is ..

views.py

JavaScript

Terminal output (hangs here)

JavaScript

Advertisement

Answer

Django loads (imports) files based on its settings.

When you put this while loop in a global scope, it is executed on import. It runs the while loop until it’s done. And it’s never done. You can add a print statement there if you want to see for yourself if that’s the root cause.

Normally people use periodic_tasks from celery but it might be an overkill for your needs.

I’d rather advise to create a command so you could run python manage.py test_task and on the os level just add a cron job that will run this command every 10 minutes.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement