Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33392

Re: Detect file is locked - windows

From aahz@pythoncraft.com (Aahz)
Newsgroups comp.lang.python
Subject Re: Detect file is locked - windows
Date 2012-11-15 08:01 -0800
Organization The Cat & Dragon
Message-ID <k833l9$8e4$1@panix5.panix.com> (permalink)
References <2af436e3-1336-42ae-aa2f-9e33135a3f2c@googlegroups.com> <mailman.3676.1352887368.27098.python-list@python.org>

Show all headers | View raw


In article <mailman.3676.1352887368.27098.python-list@python.org>,
Tim Golden  <mail@timgolden.me.uk> wrote:
>On 14/11/2012 00:33, Ali Akhavan wrote:
>>
>> I am trying to open a file in 'w' mode open('file', 'wb'). open()
>> will throw with IOError with errno 13 if the file is locked by
>> another application or if user does not have permission to open/write
>> to the file.
>> 
>> How can I distinguish these two cases ? Namely, if some application
>> has the file open or not.
>
>Can I ask what you expect to do differently in each of those cases? In
>other words, if you can't access the file, you can't access it. (Not to
>dismiss your question; I just wonder how you're going to handle the
>different cases)

Real-life use case for user-requested operation: if no permission, skip
the file "permanently" (until it changes, at least); if locked, place in
retry loop.

And in response to your other post, you absolutely want to use
CreateFileW()...  ;-)
-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/

"LL YR VWL R BLNG T S"  -- www.nancybuttons.com

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Detect file is locked - windows Ali Akhavan <a.akhavan.b@gmail.com> - 2012-11-13 16:33 -0800
  Re: Detect file is locked - windows Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-14 01:14 +0000
    Re: Detect file is locked - windows Hans Mulder <hansmu@xs4all.nl> - 2012-11-14 09:55 +0100
      Re: Detect file is locked - windows Tim Golden <mail@timgolden.me.uk> - 2012-11-14 09:06 +0000
  Re: Detect file is locked - windows Tim Golden <mail@timgolden.me.uk> - 2012-11-14 10:02 +0000
    Re: Detect file is locked - windows Hans Mulder <hansmu@xs4all.nl> - 2012-11-14 12:51 +0100
      Re: Detect file is locked - windows Tim Golden <mail@timgolden.me.uk> - 2012-11-14 12:09 +0000
    Re: Detect file is locked - windows aahz@pythoncraft.com (Aahz) - 2012-11-15 08:01 -0800
  Re: Detect file is locked - windows Tim Golden <mail@timgolden.me.uk> - 2012-11-14 11:50 +0000

csiph-web