0

I am using a package to send request needed to the front end, but I discovered that the package was blocking all other operations taking place in the server even the loading of a new page, so the server does not respond to any request until the package is through.

Please how can I get the server to run multiple processes while the package is running. This is my code

from django_eventstream import send_event#this is the package

send_event('test', 'message', "Time spent processing the data "+ x+" mins"))// No other operation responds while this one is running

So anytime that this code is running all other operation does not run

S Dra
  • 147
  • 9
  • Celery will be a good choice for handling asynchronous tasks. It will be challenging in the beginning to implement, but "celery" would be the best option to achieve asynchronous tasks – B.Anup Apr 03 '22 at 07:08
  • @B.Anup please I am a little off on how to go about it please can u shed a little more light on it? – S Dra Apr 03 '22 at 08:10
  • consider you have a form that requires input from user. Once the user submits form, you need to process the form in background without effecting the exisitng operations. If we implement celery for this scenario, as soon as the form is validated and submitted, a task will be added to the redis queue, and the functions that process these form input will be executed in background, so user won't be blocked. All these happens in the background, after the form is processed, you can post the results in the model. This is generic example to understand one of the scenario where celery can be used. – B.Anup Apr 03 '22 at 08:16
  • It is difficult to explain entire implmentation of the celery over here. I would request you to go through the below links, that will provide some understanding on celery usage for asynchronous tasks then compare that with in-build django asynchronous tasks. Then you can take a call on the implementation of celery or using in-built django async tasks feature. https://realpython.com/asynchronous-tasks-with-django-and-celery/ https://realpython.com/asynchronous-tasks-with-django-and-celery/ – B.Anup Apr 03 '22 at 08:18
  • @B.Anup From the statement, do you mean I would have to use redis in order to use of celery? I have worked with the url you gave me but the example is outdated e.g. `from celery.decorators import task` is giving error `ModuleNotFoundError: No module named 'celery.decorators'` – S Dra Apr 03 '22 at 15:53
  • - https://www.accordbox.com/blog/how-to-setup-celery-django/ - https://docs.celeryq.dev/en/latest/userguide/index.html - https://docs.celeryq.dev/en/latest/index.html – B.Anup Apr 04 '22 at 02:48
  • @B.Anup Thanks I have actually installed celery but https://realpython.com/asynchronous-tasks-with-django-and-celery/ is showing installation for an old one not reccent as such so some of the errors are showing up as stated earlier – S Dra Apr 04 '22 at 03:44
  • that realpython link is only for reference on how can you integrate django with celery. You have to refer the original celery documentation for latest packages and feature. – B.Anup Apr 04 '22 at 03:47
  • @B.Anup yeah thanks I am very grateful. I will update you if it works. Really appreciate all the effort – S Dra Apr 04 '22 at 03:51
  • @B.Anup I am not getting a hand on it – S Dra Apr 04 '22 at 08:35

0 Answers0