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


Groups > comp.lang.python > #51527

Re: timing issue: shutil.rmtree and os.makedirs

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.109.133.83.MISMATCH!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'finished,': 0.07; 'subject:skip:s 10': 0.07; 'test,': 0.07; 'executed': 0.09; 'suppress': 0.09; 'def': 0.12; 'exists,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function;': 0.16; 'instance:': 0.16; 'path:': 0.16; 'subject:issue': 0.16; 'subject:timing': 0.16; 'wrote:': 0.18; 'bit': 0.19; "skip:' 30": 0.19; 'error': 0.23; 'mon,': 0.24; "haven't": 0.24; 'permission': 0.26; 'possibly': 0.26; 'skip:" 30': 0.26; 'skip:" 40': 0.26; 'pass': 0.26; 'header:In-Reply- To:1': 0.27; 'tim': 0.29; 'errors': 0.30; 'message- id:@mail.gmail.com': 0.30; "skip:' 10": 0.31; '(since': 0.31; 'directory,': 0.31; 'exceptions': 0.31; 'raised': 0.31; 'file': 0.32; 'there.': 0.32; "i'd": 0.34; 'problem': 0.35; 'created': 0.35; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'remote': 0.38; 'skip:o 20': 0.38; 'handle': 0.38; 'whatever': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'remove': 0.60; 'removing': 0.60; 'then,': 0.60; 'new': 0.61; 'first': 0.61; 'name': 0.63; 'worth': 0.66; 'jul': 0.74; 'removal': 0.74; 'mount': 0.93; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=KfR3FrqaQDRPfNSJBiJY4FrUDh486ajpgj8r3Eo6JbA=; b=duFxINIU3WB9rVkxheSsYlEOX6nd9mA9lvUZZDkmFqzMgSV0Pn0eq/FTy9gKmpELxp 0uhbxfE7Ssx01Tc5Mc4fKJVkCWWn8PhqwmwKvQg31kQx+dNBCmMW92+dG9Z23J/2aOXL wsTJGkmxLWjIUFNecueAb2aQLuLdm1rsBqSnlI5N3QdXKZNHJumpJRzOVwgI9DGvb9yi 1Va3nZaQ2X9WIW410rNLWoK7kyEoRT3DcCEojNAucZLOMGpoMTlYqzthUBVn0OUNHD+F KBoVz38tdlCt5cGMje6AP7PxmRlB43sZOVJ/b7gmySHEZS7zRULcW7qQD2P/HGLqhn8d M+KA==
MIME-Version 1.0
X-Received by 10.52.178.194 with SMTP id da2mr11525994vdc.28.1375141956594; Mon, 29 Jul 2013 16:52:36 -0700 (PDT)
In-Reply-To <fd605b09-ce7d-4c33-922d-57f423a09556@googlegroups.com>
References <fd605b09-ce7d-4c33-922d-57f423a09556@googlegroups.com>
Date Tue, 30 Jul 2013 00:52:36 +0100
Subject Re: timing issue: shutil.rmtree and os.makedirs
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5292.1375141959.3114.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375141959 news.xs4all.nl 15914 [2001:888:2000:d::a6]:52545
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51527

Show key headers only | View raw


On Mon, Jul 29, 2013 at 8:16 PM, Tim <jtim.arnold@gmail.com> wrote:
> My intent is to pass it a directory name or path and if it exists, use shutil.rmtree to remove whatever is there (if it isn't a directory, try to unlink it); then use os.makedirs to create a new directory or path:
>
> def make_clean_dir(directory):
>     if os.path.exists(directory):
>         if os.path.isdir(directory):
>             shutil.rmtree(directory)
>         else:
>             os.unlink(directory)
>     os.makedirs(directory)
>
> The last bit of the traceback is:
> File "/develop/myproject/helpers/__init__.py", line 35, in make_clean_dir
>     os.makedirs(directory)
>   File "/usr/local/lib/python2.7/os.py", line 157, in makedirs
>     mkdir(name, mode)
> OSError: [Errno 17] File exists: '/users/tim/testing/testing_html'
>
> The directory 'testing_html' existed when I executed the function;

First thing I'd check is: Did rmtree succeed? Try removing the
makedirs and test it again; then, when your process has completely
finished, see if the directory is there. If it is, the problem is in
rmtree - for instance:

* You might not have permission to remove everything
* There might be a messed-up object in the file system
* If the directory is a remote share mount point, the other end might
have lied about the removal
* Something might have been created inside the directory during the removal
* Myriad other possibilities

As I understand rmtree's docs, any errors *that it detects* will be
raised as exceptions (since you haven't told it to suppress or handle
them), but possibly there's an error that it isn't able to detect.
Worth a test, anyhow.

ChrisA

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


Thread

timing issue: shutil.rmtree and os.makedirs Tim <jtim.arnold@gmail.com> - 2013-07-29 12:16 -0700
  Re: timing issue: shutil.rmtree and os.makedirs Chris Angelico <rosuav@gmail.com> - 2013-07-30 00:52 +0100
    Re: timing issue: shutil.rmtree and os.makedirs Tim <jtim.arnold@gmail.com> - 2013-07-30 06:10 -0700
      Re: timing issue: shutil.rmtree and os.makedirs Chris Angelico <rosuav@gmail.com> - 2013-07-30 14:27 +0100
        Re: timing issue: shutil.rmtree and os.makedirs Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-30 14:07 +0000
          Re: timing issue: shutil.rmtree and os.makedirs Chris Angelico <rosuav@gmail.com> - 2013-07-30 15:47 +0100
        Re: timing issue: shutil.rmtree and os.makedirs Tim <jtim.arnold@gmail.com> - 2013-07-30 08:37 -0700
          Re: timing issue: shutil.rmtree and os.makedirs Chris Angelico <rosuav@gmail.com> - 2013-07-30 17:03 +0100
      Re: timing issue: shutil.rmtree and os.makedirs Göktuğ Kayaalp <goktug.kayaalp@gmail.com> - 2013-07-30 20:09 +0300

csiph-web