Google App Engine urlfetch DeadlineExceededError in push task handler running apiclient batch request
<p>I have a task handler that is making a batch request to the Google Calendar API. After 5 seconds, the request fails with <em>DeadlineExceededError: The API call urlfetch.Fetch() took too long to respond and was cancelled.</em>  I have changed <code>urlfetch.set_default_fetch_deadline(60)</code> near where I make the batch request, as suggested <a href="http://stackoverflow.com/questions/13051628/gae-appengine-deadlineexceedederror-deadline-exceeded-while-waiting-for-htt">here</a> but it does not seem to make a difference: the deadline seems to remain 5 seconds.</p>

<p>I am using the Python Google API Client library which sits on top of oauth2client and httplib2. But my understanding is that GAE intercepts the underlying calls to use urlfetch.Fetch. This is what the stack trace seems to show as well. </p>

<p>Can you see any reason why <code>urlfetch.set_default_fetch_deadline</code> does not seem to be working?</p>

<h2>EDIT:</h2>

<p>This is the code used to build the batch request:</p>

<pre><code># note `http` is a oauth2client authorized http client
cal = apiclient.discovery.build('calendar','v3',http=http)
req = cal.new_batch_http_request(callback=_callback)
for event in events:   # anything larger than ~5 events in batch takes &gt;5 secs
  req.add( 
    cal.events().patch(calendarId=calid, eventId=event["id"], body=self._value) 
  )
urlfetch.set_default_fetch_deadline(60)  # has no effect
req.execute()
</code></pre>

<p>So, <code>urlfetch.set_default_fetch_deadline()</code> did eventually work for me. The problem was my underlying http client (oauth2client / httplib2) was essentially stored in a global. Once I created it in the task handler thread the <code>set_default_fetch_deadline</code> worked.</p>

python google-app-engine google-api google-calendar task-queue