[python-win32] pure python way to open a file with write deny for others

Tim Roberts timr at probo.com
Fri Mar 6 15:05:01 EST 2020


Robin Becker wrote:
> On 05/03/2020 16:04, Eryk Sun wrote:
>> On 3/5/20, Robin Becker <robin at reportlab.com> wrote:
>>> I want to be able to read a windows file which is being periodically 
>>> written
>>> by another process.
>>
>> I'm having difficulty reconciling this sentence with the subject line.
>
> OK I want to read the (small) file completely. The other process may 
> try to re-write the file while I am reading it. I thought that denying 
> them write permission for the short time I have the file open for 
> reading might make incomplete files less likely. So far the 
> applications seem to be able to operate in this fashion and the small 
> files seem to be complete.

Remember that the "deny write" permission only applies to opens. And if 
you have "deny write" set, the other open will fail -- it won't just delay.

You can always use win32file.CreateFile directly, and bypass the Python 
filtering.  Alternatively, and perhaps more hacky, you can use 
subprocess to copy the file to a safe temporary name.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3389 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-win32/attachments/20200306/e87624cf/attachment.bin>


More information about the python-win32 mailing list