3

I have a webhook which takes a little time to complete (around 5 minutes). However, the request gets timeout after around 30 seconds.

I am on a shared hosting with HostGator and using FCGI for deployment.

I think the request gets timed-out as there is not HTTPResponse until the request is processed. If I can generate some HTTPResponse from view while the request is processed, the script might be able to run longer.

[P.S.: Earlier I tried Google App Engine, where using print 'hi' would print 'hi' in browser instead of logging it. Is the same possible with Django. Doing so might send response even while the request completes.] (I was told on Django IRC that even I was able to get print to send message as response, it will only throw out when Httpresponse is returned.) Thus it was suggested to use Httpresponse with an iterable.

Pratyush
  • 5,108
  • 6
  • 41
  • 63

2 Answers2

4

Timeout is in webserver, not in Django. You make a request to webserver and get a response from it, so you can't get anything outside of that response. In your case you should create a background task on server, usually getting started by cron or celery (it hink you can't run celery on hostgator so use cron) with a queue of tasks. On the cliend side you periodically make requests to server using AJAX, so you can check status of a task and display notification if it is completed.

ilvar
  • 5,718
  • 1
  • 20
  • 17
  • Hi ilavar, yes the timeout is from apache server and not from Django. But the timeout was caused as there was no reply from Django script for more than 30 seconds (since it throws output only after processing). It was already a webhook (as also used by Celery or other queue programs). The problem was solved by using HttpResponse in iterable (as suggested on IRC). Will post it here soon. – Pratyush Mar 13 '12 at 18:54
3

The guys at Django IRC told to use HttpResponse with a generator to continuously send an output and thus prevent the script from idle-timeout.

The code for using Httpresponse with generator has been wonderfully described here and here.

Thanks everyone!

Community
  • 1
  • 1
Pratyush
  • 5,108
  • 6
  • 41
  • 63