[Python-Dev] Python 2.5.1

Alexey Borzenkov snaury at gmail.com
Mon Apr 30 09:47:55 CEST 2007

Hi Martin,

On 4/29/07, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> The error Windows reports is ERROR_SHARING_VIOLATION. I never
> understood sharing fully, but it may be that if the file is opened
> in "exclusive sharing", stat'ing it may fail.

Sharing is actually very easy. If you didn't specify
SHARE_READ/SHARE_WRITE/SHARE_DELETE when opening the file and you
succeeded, then any process can't read/write/delete the file until you
close the handle.

> I personally consider it a bug in Windows that you cannot get file
> attributes if some other process has opened it. Exclusive access
> should only restrict access to file contents, but not file attributes.

After doing some research I found that it seems to be impossible to
use CreateFile for a file that doesn't have SHARE_READ. I played with
different combinations and with FLAG_BACKUP_SEMANTICS and nothing
helped. However on Windows there's still a possibility to read
attributes: use FindFirstFile. _WIN32_FIND_DATA structure seems to
have all the necessary fields (attributes, file times, size and
full/short filename), and FindFirstFile doesn't care about sharing at

More information about the Python-Dev mailing list