添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
风流倜傥的蛋挞  ·  Receiving Error: ...·  1 周前    · 
才高八斗的骆驼  ·  ImportError: ...·  6 天前    · 
鬼畜的山羊  ·  iPhone SE - Apple (中国大陆)·  2 月前    · 
豪情万千的麻辣香锅  ·  USRP B200/B210 ...·  3 月前    · 
睿智的伤疤  ·  天津大学-化工学院·  9 月前    · 
个性的紫菜汤  ·  worldpay payment ...·  1 年前    · 

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I start a python thread to calculate data and set to Redis.

I found about 30 minutes, will throw a exception:

self.pipe.execute()
File "/usr/local/lib/python3.4/dist-packages/redis/client.py", line 2626, in execute
return execute(conn, stack, raise_on_error)
File "/usr/local/lib/python3.4/dist-packages/redis/client.py", line 2503, in execute_transaction
self.parse_response(connection, '
')
File "/usr/local/lib/python3.4/dist-packages/redis/client.py", line 2584, in parse_response
self, connection, command_name, **options)
File "/usr/local/lib/python3.4/dist-packages/redis/client.py", line 585, in parse_response
response = connection.read_response()
File "/usr/local/lib/python3.4/dist-packages/redis/connection.py", line 577, in read_response
response = self._parser.read_response()
File "/usr/local/lib/python3.4/dist-packages/redis/connection.py", line 238, in read_response
response = self._buffer.readline()
File "/usr/local/lib/python3.4/dist-packages/redis/connection.py", line 168, in readline
self._read_from_socket()
File "/usr/local/lib/python3.4/dist-packages/redis/connection.py", line 130, in _read_from_socket
buf.write(data)
ValueError: I/O operation on closed file.

It looks like socket connection disconnect ?

class KVStore:

def __init__(self, host, port, password):
    self.r = redis.StrictRedis(host=host, port=port, password=password)
    self.pipe = self.r.pipeline()
    self.set_count = 0
    self.MAX_SET = 1000
def set(self, key, value, timeout=None, force=None):
    if force is None:
        force = False
    self.pipe.set(key, o2s(value), timeout)
    self.set_count += 1
    if force:
        self.submit()
    else:
        if self.set_count > self.MAX_SET:
            self.submit()
def submit(self):
    if self.set_count != 0:
        #logger.debug('kv_store|submit|%d', self.set_count)
        self.pipe.execute()
        self.set_count = 0
def get(self, key):
    value = self.r.get(key)
    return s2o(value)
def delete(self, key):
    self.r.delete(key)
def exists(self, key):
    return self.r.exists(key)
def count(self):
    return self.r.dbsize()

repeat set key value, and submit.