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


Groups > comp.lang.python > #33328

Re: Detect file is locked - windows

Date 2012-11-14 12:09 +0000
From Tim Golden <mail@timgolden.me.uk>
Subject Re: Detect file is locked - windows
References <2af436e3-1336-42ae-aa2f-9e33135a3f2c@googlegroups.com> <mailman.3676.1352887368.27098.python-list@python.org> <50a385a5$0$6916$e4fe514c@news2.news.xs4all.nl>
Newsgroups comp.lang.python
Message-ID <mailman.3680.1352894950.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 14/11/2012 11:51, Hans Mulder wrote:
> It would be nice if he could give specific error messages, e.g.
> 
>     "Can't write %s because it is locked by %s."
> 
> vs.
> 
>     "Can't write %s because you don't have write access."
> 
> I can't speak for Ali, but I'm always annoyed by error messages
> listing several possible cuases, such as "Can't delete file,
> because the source or destination is in use".

(I realise you're not demanding this particular behaviour from Python
but just to expand on what the obstacles are to this at present):

Speaking merely from the point of view of the current Python
implementation on Windows, there are two obstacles to this:

* Python calls into the CRT which simply returns 13 (EACCESS) for both
of these situations. Obviously, Python could do its own thing on
Windows, partly reimplementing what the CRT does anyway and giving more
precise feedback. Equally obviously, this wouldn't be a trivial exercise.

* The added information -- who's locked the file, what permissions are
in place which prevent you gaining the requested access -- is
surprisingly fiddly to get hold of and would be something of an overhead
for the majority of the time when it's not wanted. Of course, in this
hypothetical Python one could add some sort of flag to the open()
function which requested or not the additional information.

The first obstacle is more significant than the second but neither is
negligible.

TJG

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