#lists client information import fcntl import json import os def read_data(): try: with open('/tmp/ssh_sessions.json', 'r') as f: # Get shared lock for reading fcntl.flock(f.fileno(), fcntl.LOCK_SH) try: return json.load(f) finally: fcntl.flock(f.fileno(), fcntl.LOCK_UN) except (FileNotFoundError, ValueError): return {} print(read_data())