Using asynchronous background tasks for resource-intensive computations
There are implementations of many approximation algorithms and P-complete problems that can create memory-related issues, thread problems, or even memory leaks. To avoid imminent problems when handling solutions for NP-hard problems with indefinite data sets, implement the solutions using asynchronous background tasks.
But first, install the celery
client using the pip
command:
pip install celery
Also, install the Redis database server for its broker. Place celery_config.py
, which contains celery_init_app()
, in the project directory and call the method in the main.py
module.
After the setup and installations, create a service package in the Blueprint
module folder. ch06-project
has the following Celery task in the hpi_formula.py
service module found in the internal
Blueprint module:
@shared_task(ignore_result=False) def compute_hpi_laspeyre(df_json): async def compute_hpi_task...