应用是 webapp2 + gevent 做的. 应用有需要用 gevent 进行的异步操作, 所以无法使用 libmemcached 的 bindings. 使用 Dozer 已经确认泄漏出现在 memcache.Client. python-memcache 版本 1.40-2ubuntu1, python 版本 2.6.4~rc2-0ubuntu1.
大致目前的使用方式:
def get_mc():
mc = memcache.Client([MEMCACHE_SERVER], debug=0)
return mc
... (略)
def mc_free(mc):
mc.disconnect_all()
然后
mc = get_mc()
...
mc_free(mc)
del mc
但不幸的是该 object 仍然没有被回收.
全局的 memcache.Client 实例, 在同时被使用(gevent)时会引发竞态(也不适合加锁), 故提此问题.
大致目前的使用方式:
def get_mc():
mc = memcache.Client([MEMCACHE_SERVER], debug=0)
return mc
... (略)
def mc_free(mc):
mc.disconnect_all()
然后
mc = get_mc()
...
mc_free(mc)
del mc
但不幸的是该 object 仍然没有被回收.
全局的 memcache.Client 实例, 在同时被使用(gevent)时会引发竞态(也不适合加锁), 故提此问题.