I already checked out Python : Check file is locked and How to check whether a file is_open and the open_status in python. Generally, the following code suits my need, but it doesn't work in Python 2 for Unicode strings.
from ctypes import cdll
_sopen = cdll.msvcrt._sopen
_close = cdll.msvcrt._close
_SH_DENYRW = 0x10
def is_open(filename):
h = _sopen(filename, 0, _SH_DENYRW, 0)
try:
return h == -1
finally:
_close(h)
Any suggestions what I should do?