Question

I'm working on a web application with Python and Google App Engine.

I tried to set the default URLFetch deadline globally as suggested in a previous thread:

https://stackoverflow.com/a/14698687/2653179

urlfetch.set_default_fetch_deadline(45)

However it doesn't work - When I print its value in one of the functions: urlfetch.get_default_fetch_deadline() is None.

Here is main.py:

from google.appengine.api import users
import webapp2
import jinja2
import random
import string
import hashlib
import CQutils
import time
import os
import httpRequests
import logging
from google.appengine.api import urlfetch
urlfetch.set_default_fetch_deadline(45)

...

class Del(webapp2.RequestHandler):
    def get(self):
        id = self.request.get('id')
        ext = self.request.get('ext')
        user_id = httpRequests.advance(id,ext)
        d2 = urlfetch.get_default_fetch_deadline()
        logging.debug("value of deadline = %s", d2)

Prints in the Log console:

DEBUG    2013-09-05 07:38:21,654 main.py:427] value of deadline = None

The function which is being called in httpRequests.py:

def advance(id, ext=None):

    url = "http://localhost:8080/api/" + id + "/advance"

    if ext is None:
        ext = ""

    params = urllib.urlencode({'ext': ext})
    result = urlfetch.fetch(url=url,
                            payload=params,
                            method=urlfetch.POST,
                            headers={'Content-Type': 'application/x-www-form-urlencoded'})

    if (result.status_code == 200):
        return result.content
Was it helpful?

Solution

I know this is an old question, but recently ran into the issue.

The setting is placed into a thread-local, meaning that if your application is set to thread-safe and you handle a request in a different thread than the one you set the default deadline for, it can be lost. For me, the solution was to set the deadline before every request as part of the middleware chain.

This is not documented, and required looking through the source to figure it out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top