截止日期=无使用后urlfetch.set_default_fetch_deadline(n) [英] deadline = None after using urlfetch.set_default_fetch_deadline(n)

查看:112
本文介绍了截止日期=无使用后urlfetch.set_default_fetch_deadline(n)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python和Google App Engine开发Web应用程序。



我尝试按照上一个线程中的建议设置全局默认URLFetch截止日期: / p>

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

  urlfetch.set_default_fetch_deadline(45)

但是它不起作用 - 当我在其中一个函数中打印它的值时:urlfetch.get_default_fetch_deadline()是None。



以下是main.py:

  from google.appengine.api导入用户
导入webapp2
导入jinja2
导入随机
导入字符串
导入hashlib
导入CQutils
导入时间
导入os
导入httpRequests
导入记录
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(截止日期值=%s,d2)



  DEBUG 2013-09-05 07:38:21,654 main.py:427]截止日期的值= None 

在httpRequests.py中调用的函数:

  def advance(id,ext = None):
$ b $ url url =http:// localhost:8080 / api / + id +/ advance

如果分机是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


解决方案我知道这是一个老问题,但最近碰到了这个问题。



该设置被放置到一个线程本地,这意味着如果您的应用程序被设置为线程安全,并且您在与设置默认截止日期的线程不同的线程中处理请求,则该请求可能会丢失。对我而言,解决方案是在每个请求之前设置最终期限,作为中间件链的一部分。



这没有记录,需要通过源代码查找。


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

解决方案

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.

这篇关于截止日期=无使用后urlfetch.set_default_fetch_deadline(n)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆