1

I have a django web application and I have to create model for Machine Learning in a view.

It takes a long time so PythonAnyWhere does not allow it and it kills the process when it reaches 300 seconds. According to that, i want to ask two questions.

  1. Without celery, django bg task or something else, my view which contains the long running process does not work in order. But when I use debugger, it works correctly. Probably, some lines of code try to work without waiting for each other without debugger. How can i fix this?

  2. PythonAnyWhere does not support celery or other long running task packages. They suggest django-background-tasks but in its documentation, the usage is not explained clearly. So I could not integrate it. How can i integrate django-background-tasks?

Thank you.

tejas
  • 1,795
  • 1
  • 16
  • 34
Aslı Kök
  • 616
  • 8
  • 19
  • Go to a hosting provider that allows you to use celery. pythonanywhere wasn't designed for this kind of purpose. – dirkgroten Feb 24 '20 at 15:07
  • 1. I don't understand what you mean by "when I use debugger". On your local machine? And no, python/django is sequential so no line of code will ever be executed without the previous finished (unless you explicitly use asyncio). 2. The purpose of django-background-tasks is not really to run long-running processes in the background, and if python anywhere doesn't allow process to run longer than 300 seconds, it won't help anyway. – dirkgroten Feb 24 '20 at 15:14
  • 1
    Probably Django's view is not the correct place to do this. HTTP requests should usually complete quickly and return a response. – tejas Feb 24 '20 at 15:15
  • When I check the app on local with debugger, the code runs line by line. But when i run the app and i try to do the same process on web page by pressing button, the code does not work line by line. I cannot find its reason. – Aslı Kök Feb 24 '20 at 18:38
  • 1
    Code in a PythonAnywhere web app can *only* run line-by-line because it's single-threaded. Perhaps you have data that is different between local and PythonAnywhere so the code runs on a different path than you expect. You can add debug output to your view (prints to stderr will appear in your error log) to debug the view. – Glenn Feb 25 '20 at 13:45
  • I've fixed the first issue. But I still could not integrate the bgtask. I've created the tasks.py and I've created the background function, i call it from view but the background function does not work. – Aslı Kök Feb 25 '20 at 14:36
  • 1
    Are you running the process_tasks management command somewhere? – Glenn Feb 27 '20 at 12:19
  • I've fixed all of the issues. Thanks. – Aslı Kök Feb 27 '20 at 12:20

0 Answers0