This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, giampaolo.rodola, paul.moore, steve.dower, tarek, tim.golden, yuliu, zach.ware
Date 2018-04-08.04:35:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1523162151.8.0.682650639539.issue33240@psf.upfronthosting.co.za>
In-reply-to
Content
This is not an uncommon problem. If there's one or more existing references to a file or empty directory that were opened with shared delete access, then a delete operation will succeed, but the file or directory will not be unlinked from the parent directory. The filesystem only unlinks a file or directory if its "delete disposition" is set when the last reference is closed. 

Removing the parent directory thus requires a loop that retries the delete until it succeeds, i.e. until existing references are closed and the directory finally becomes empty and thus deletable. If the problem is caused by an anti-malware program, it should typically be resolved within a short time. Exactly how long to wait in a retry loop before failing the operation should be configurable.

Maybe you can conduct a simple experiment to measure the wait time required in your case. Run the following with "bar" opened in Explorer. Substitute the real path of "foo" in PARENT_PATH.

    import os
    import time

    ERROR_DIR_NOT_EMPTY = 145

    PARENT_PATH = 'foo'
    CHILD_PATH = os.path.join(PARENT_PATH, 'bar')

    os.rmdir(CHILD_PATH)
    t0 = time.perf_counter()

    while True:
        try:
            os.rmdir(PARENT_PATH)
            wait_time = time.perf_counter() - t0
            break
        except OSError as e:
            if e.winerror != ERROR_DIR_NOT_EMPTY:
               raise

    print(wait_time)
History
Date User Action Args
2018-04-08 04:35:51eryksunsetrecipients: + eryksun, paul.moore, giampaolo.rodola, tim.golden, tarek, zach.ware, steve.dower, yuliu
2018-04-08 04:35:51eryksunsetmessageid: <1523162151.8.0.682650639539.issue33240@psf.upfronthosting.co.za>
2018-04-08 04:35:51eryksunlinkissue33240 messages
2018-04-08 04:35:50eryksuncreate