_SH_DENYRW = 16

def is_open(filename):
    if not os.access(filename, os.F_OK):
        return False
h = _sopen(filename, 0, _SH_DENYRW, 0)
if h == 3:
    _close(h)
return False
return True
How to check whether a file is_open and the open_status in python