This is an archive of the discontinued LLVM Phabricator instance.

Fixed a problem removing temp files
ClosedPublic

Authored by PeteSteinfeld on May 12 2020, 1:17 PM.

Details

Summary

Before making this change, whenever I ran "check-flang", I'd get an
error message like:

llvm-lit: /mnt/c/GitHub/f18/c751/flang/build/bin/../../../llvm/utils/lit/lit/main.py:252: warning: Failed to delete temp directory '/tmp/lit_tmp_gOKUIh'

With this change, there's no such message in the output, and the temp
directory is successfully removed.

Note that my working environment is on Windows 10 running Windows
Subsystem for Linux using the Ubuntu app.

Diff Detail

Event Timeline

PeteSteinfeld created this revision.May 12 2020, 1:17 PM
Herald added a project: Restricted Project. · View Herald Transcript
yln added a comment.May 12 2020, 2:13 PM

Hi, thanks for tackling this!

I am not on Windows, so I can't reproduce this. Would you be able to debug this so we understand what the problem is? For example, printing the exception object or looking into the error handler of shutil.rmtree(... , onerror=..) might shed light on things [1].

The docs say that os.rmdir() raises when the directory isn't empty, so maybe it's not the best tool here.

Does the following work?

# Sleep and retry
time.sleep(2) # what would be a good value here?
shutil.rmtree(..., ignore_errors=True)

Thanks!

I am not on Windows, so I can't reproduce this. Would you be able to debug this so we understand what the problem is? For example, printing the exception object or looking into the error handler of shutil.rmtree(... , onerror=..) might shed light on things [1].

Here's what I've discovered.

Despite the FIXME comment, inserting a call to sleep() has no effect.

I printed out the exception object, and got the following:

'module' object has no attribute 'rmtree'

When I moved the call to shutil.rmtree() out of the try/exception block, I got a stack dump the message at the bottom:

NameError: global name 'shutil' is not defined

So the version of Python I'm using doesn't have shutil. When I look up the documentation, it looks like it's been around since at least version 2.3, and I'm running version 2.7.1. I also have version 3.6.7 on my machine, and when I upgraded to that version the problem went away.

I'm not sure what the best fix is here. The simplest thing for me would be to
remove the FIXME comment and add some text to the warning message recommending that the user upgrade their version of Python if they see the message.

I put in such code and tested it under both Python 2.7.1 and 3.6.7, and it works for me.

yln added a comment.May 13 2020, 11:11 AM

'module' object has no attribute 'rmtree'

So on Windows in Python2, rmtree() is not available? This surprises me (it's not mentioned in the docs). It also means the FIXME drew the wrong conclusion.

When I moved the call to shutil.rmtree() out of the try/exception block, I got a stack dump the message at the bottom:
NameError: global name 'shutil' is not defined

I think this means that the import statement is missing. Try to also move the import shutil.

The simplest thing for me would be to remove the FIXME comment and add some text to the warning message recommending that the user upgrade their version of Python if they see the message.

I put in such code and tested it under both Python 2.7.1 and 3.6.7, and it works for me.

Cool, thanks!

yln resigned from this revision.May 14 2020, 12:45 PM
PeteSteinfeld accepted this revision.May 15 2020, 1:06 PM
This revision is now accepted and ready to land.May 15 2020, 1:06 PM
PeteSteinfeld closed this revision.May 15 2020, 1:07 PM