desolat
desolat

Reputation: 4163

Non-intrusively unlock file on Windows

Is there a way to unlock a file on Windows with a Python script? The file is exclusively locked by another process. I need a solution without killing or interupting the locking process.

I already had a look at portalocker, a portable locking implementation. But this needs a file handle to unlock, which I can not get, as the file is already locked by the locking process.

If there is no way, could someone lead me to the Windows API doc which describes the problem further?

Upvotes: 2

Views: 3955

Answers (2)

Komat
Komat

Reputation: 325

If you only need to infrequently read the locked file, you might try to use the Volume Shadow Copy Service

Upvotes: 1

mmmmmm
mmmmmm

Reputation: 32710

Anything you do will affect the other process if that process thinks it has a lock on the file then breaking the lock means that the program has unexpected brhaviour and could brek or corrupt things.

Thus only do this if you know exactly what will happen.

The api used by the other program probably uses msdn LockFile

Upvotes: 1

Related Questions