Django increases asynchronous tasks with multithreading

Source: Internet
Author: User

See Django Async Everyone's reaction should be celery this Message Queuing component, now with the most recommended is also this way. However, I demand this is the request to execute a small program, but can not be sure when the small program execution, response and timely, throw to queue processing of course, but for the sake of simplicity, decided to run a thread directly. (Of course, this is only an experiment, the application size is also very small, if the concurrency is high, there will be many problems)


This code was intercepted from view.py:

    @login_required    def search_area (request):        prints = Printthread ()        Prints.start ()        return Retrieve ( Request, ' area ', ' areasearche.html ', [{' Name ': ' areaname ', ' mode ': ' contains '}]    # #通过thread implement Django    Import Threading    Import Time    class Printthread (threading. Thread):        def run (self):            print "Start .....%s"% (Self.getname (),) for            I in range:                time.sleep (1)                Print i            print "End .....%s"% (Self.getname (),)

From the results of the implementation of the requirements can be completed,
    Start .... Thread-7    0    1    2    [24/oct/2014 15:09:30] "get/media/js/hawk.js http/1.1" 304 0    3    ...    The    end .... Thread-7

For timed-delay tasks, there are also aspects of high-concurrency asynchronous tasks that are used by MQ.


This article is from the "Orangleliu Notebook" blog, reproduced please be sure to keep this source http://blog.csdn.net/orangleliu/article/details/41961295

Author Orangleliu using Attribution-NonCommercial-sharing protocol in the same way


Django increases asynchronous tasks with multithreading

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.