Closed vit1251 closed 2 years ago
Do the msvcrt.locking() calls not work? Does the os.fdopen() call not work? Have you error messages?
@pixelb you have in self.fp object
Second, windows implementation has no sameopenfile implementation.. And as result you tools does not work.
Ah I see tricky. The documentation uses the same 'fd' parameter name for lockf() and locking()
As for the sameopenfile() issue, that shouldn't be possible anyway on windows, so can you change that part to:
if (os.name == 'nt'
or os.path.sameopenfile(self.fp.fileno(), fpnew.fileno())):
I'll commit both changes in your name if it works.
thanks!
@pixelb usually I create a separate classes int-t from FileLock for example you may Implement WindowsFileLock and PosixFileLock.
N.B. os.path.sameopenfile you really require this call? You may just read all information to memory and write it again back with exclusive lock. And most of INI files must small size and just load in memory.
Having separate classes seems like a little overkill here. I'll consider cleaning up, though will mean moving the if os == 'nt' call to a higher level.
We need the sameopenfile() check to ensure we're locking on the right file. Note the read() is done after the locking.
Addressed in commit 0f2c0b03
You will use follow code
Also
It does not work on WIndows platform!!!
This code have two or three level simplify ready at now...