What is Django's behavior when a request is interrupted?

339 views
Skip to first unread message

John Boxall

unread,
May 29, 2012, 12:23:54 PM5/29/12
to django...@googlegroups.com
Consider the following code:

    def view(request):
        import pdb;pdb.set_trace()
        # Make a bunch of databases updates
        return HttpResponse('OKAY')

I boot up the Django devserver and make a request from my browser. It is routed by Django to `view`. When the debugger launches, I cancel the request in my browser.

It seems as though Django continues executing the code in the request path. Is this the expected behavior?

If the connection has 'gone away' are there any circumstances where Django will raise an exception in the regular request path?

Cheers,

John

Ian Clelland

unread,
May 29, 2012, 2:39:08 PM5/29/12
to django...@googlegroups.com


On Tuesday, May 29, 2012, John Boxall wrote:
Consider the following code:

    def view(request):
        import pdb;pdb.set_trace()
        # Make a bunch of databases updates
        return HttpResponse('OKAY')

I boot up the Django devserver and make a request from my browser. It is routed by Django to `view`. When the debugger launches, I cancel the request in my browser.

It seems as though Django continues executing the code in the request path. Is this the expected behavior?

As a WSGI application, Django should have no
idea that the connection has been closed. The connection to the client is just another resource, like a database connection or a memcache server. Nothing will happen asynchronously to raise an exception; you'll only see an exception at the point where you try to use the resource.


If the connection has 'gone away' are there any circumstances where Django will raise an exception in the regular request path?

You're only going to see an exception at the point where you try to write out to the http response object, and your wsgi server fails because the other end of the connection is closed.

In django 1.4, http response is lazy, as well, so even writing directly to it will probably not raise an exception until the view has returned, anyway.

Ian


Cheers,

John

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/M-mNNXY3vbQJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
Regards,
Ian Clelland
<clel...@gmail.com>
Reply all
Reply to author
Forward
0 new messages