2013-02-25 77 views
0

我想爲一個位置自動完成api構建一個代理/緩存服務器。下面是體現誤差幾乎所有我嘗試查詢我的服務器時間簡化代碼:Gevent崩潰python。核心傾倒(refcount太小)。怎麼了?

#!/usr/bin/python 
import gevent 
from gevent import monkey 
from gevent.wsgi import WSGIServer 
monkey.patch_all() 

import urllib2 
import urlparse 
import json 

def requestHandler(env, start_response): 
    start_response('200 OK', [('Content-Type', 'text')]) 
    parameters = urlparse.parse_qs(env['QUERY_STRING']) 

    if 'search' in parameters: 
     searchString = parameters['search'][0] 

     # Query the auto-completion server 
     json_results = urllib2.urlopen('http://autocomplete.wunderground.com/aq?query=' + searchString).read() 
     results = json.loads(unicode(json_results, "ISO-8859-1")) 

     finalResult = '' 
     for result in results['RESULTS']: 
       finalResult += result['name'] + ';' + result['c'] + ';' + result['zmw'] + ';' + result['tzs'] + ';' 

     return [finalResult.encode('utf-16')] 

    else: 
     return ['ERROR'] 

server = WSGIServer(('', 8888), requestHandler) 
print 'Server running on port 8888...' 
server.serve_forever() 

有時工作在第一查詢,但我第二次提出要求,它崩潰。有時第一次立即崩潰。這是錯誤我得到:

Modules/gcmodule.c:348: visit_decref: Assertion "gc->gc.gc_refs != 0" failed. 
refcount was too small 
object : <weakref at 0x9e0f194; to 'gevent.core.http_request' at 0x9e0a11c> 
type : weakref 
refcount: 1 
address : 0x9e0f194 
Aborted (core dumped) 

我的系統是: 的CentOS 6.3,Python的 2.6.6, GEVENT 0.13.8

是否有人有任何線索可能是錯的?似乎相當基本的東西導致這種問題...

+1

這聽起來似乎是'gevent'中的一個錯誤。解釋器中的斷言失敗意味着*必須*在某處的C代碼中出現錯誤 - 無論是在覈心Python代碼中,還是在像「gevent」這樣的庫中。 – 2013-02-25 12:44:46

回答

1

你應該升級Gevent到1.0版本,因爲錯誤已修復與垃圾回收有關。

我也見過建議在接受請求前做一個小小的睡眠。

+0

我嘗試過睡覺,沒有區別。似乎升級到1.0是唯一剩下的嘗試......但是我還是注意到了一件事,看起來這個錯誤與我在函數中使用urllib2請求有某種關係。因爲如果我省略了urllib2.urlopen並且返回一些假結果,它的工作原理是完美的......但是這使得它等於一個基本的gevent示例代碼,所以很明顯它應該可以工作,但它讓我懷疑urllib2是否是問題 – 2013-02-25 13:05:04

+0

I終於有時間用最新的Gevent 1.0進行測試了。問題沒有了。 – 2013-03-02 14:27:05