In Pylons, how do I do things after writing an answer?

In the pylons controller, I would like to first return the response to the request (so that the user receives an ASAP response), and then perform some additional operations (for example, updating the number of views, etc.) that should not occur in order to form a response. What is the best practice for such things?

Thank!

+3
source share
2 answers

On most wsgi-based servers (for example, in standard wsgiref, nwsgi, etc.) there is a way to send some of the work with the body a little more and send a few more. I suggest that "send some more" is optional.

. WSGI ( , Pylons):

def application(environ, start_response):
    start_response('200 OK', [('Content-type','text/plain')])
    yield 'body starts. You should see this in browser already'
    # do something
    yield 'some more of body'

, .

wsgi, . , Pylons.

+2

Python, - :

def controller_method(self):
    # controller logic here
    html = render('/template.mako')
    # start a thread here
    return html

, , .

RabbitMQ . -, .

0

Source: https://habr.com/ru/post/1747077/


All Articles