Python Asynchronous processing celery

Source: Internet
Author: User

Long time no Update blog, the previous period busy with the completion of the establishment, and then to the company internship. In the near period of time empty, tidy up the problems encountered before, as well as the solution.

Usually when the computer is running long code, it needs to be placed in the background for processing, that is, to implement asynchronous. One solution in Python is to use the celery package.

The implementation of the idea is that before the calculation in the database such as MONGO insert a {"state": "0"};celery put the calculation program into a database to store messages, usually can use Redis; at the same time, start celery worker, it will keep check The message inside the Redis, if any, is calculated, and when the update record {"state": "1", "result": "Something"} is completed.

The advantage of Asynchrony is the ability to put a bunch of calculation in the background, while the front end just keeps check the state of that record feature. Of course state can also have a lot of status values, you can define each error, so you can also find errors.

Python Asynchronous processing celery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.