Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51527
| References | <fd605b09-ce7d-4c33-922d-57f423a09556@googlegroups.com> |
|---|---|
| Date | 2013-07-30 00:52 +0100 |
| Subject | Re: timing issue: shutil.rmtree and os.makedirs |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5292.1375141959.3114.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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