python-memcached并发调用get/set时出现RunTimeError:Second simultaneous read on fileno 8 detected.
出现异常如下 RuntimeError: Second simultaneous read on fileno 8 detected. Unless you really know what you're doing, make sure that only one greenthread can read any particular socket. Consider using a pools.Pool. If you do know what you're doing and want to disable this error, call eventlet.debug.hub_multiple_reader_prevention(False)
class CacheBackend(CacheBackendBase): ''' Cache in memcached servers. ''' def __init__(self): self.value_length = CONF.chunkcache_memcached_value_length self.servers = CONF.chunkcache_memcached_servers @staticmethod def instance(): global CACHE_BACKEND if CACHE_BACKEND is None: CACHE_BACKEND = CacheBackend() return CACHE_BACKEND def get(self, key, default=None): client = _connect(self.servers, self.value_length) result = client.get(str(key)) client.disconnect_all() return result or default def exist(self, key): return self.get(str(key)) != None def set(self, key, value): client = _connect(self.servers, self.value_length) result = client.set(str(key), value) client.disconnect_all() if result == 0: raise exception.MemcacheSetError() return result def delete(self, key): client = _connect(self.servers, self.value_length) if self.exist(key): result = client.delete(str(key)) if result == 0: raise exception.MemcacheDeleteError() client.disconnect_all() return True def clear(self): # No need for clearing memcached. return Truedef _connect(servers, value_length=chunkstore.Store.CHUNKSIZE): return memcache.Client(servers, debug=1, server_max_value_length=value_length)