def list(self, data=None):
"""
Update asid_list file.
:param data: tuple (s_sid, target)
:return:
"""
file_path = os.path.join(running_path, '{sid}_list'.format(sid=self.sid))
if data is None:
with open(file_path, 'r') as f:
fcntl.flock(f, fcntl.LOCK_EX)
result = f.readline()
return json.loads(result)
else:
with open(file_path, 'r+') as f: # w+ causes a file reading bug
fcntl.flock(f, fcntl.LOCK_EX)
result = f.read()
if result == '':
result = {'sids': {}}
else:
result = json.loads(result)
result['sids'][data[0]] = data[1]
f.seek(0)
f.truncate()
f.write(json.dumps(result))
评论列表
文章目录