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.

Title: Add to shutil the ability to wait until files are definitely deleted
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Vivek.Balakrishnan, ezio.melotti, jkloth, loewis, rhettinger, seanmccully, serhiy.storchaka, vstinner, zach.ware
Priority: normal Keywords: easy, patch

Created on 2014-07-21 20:00 by zach.ware, last changed 2022-04-11 14:58 by admin.

File name Uploaded Description Edit
shutil_wait.patch Vivek.Balakrishnan, 2014-08-02 13:39 review
issue22024.patch seanmccully, 2014-08-22 05:28 Adds _shutil.c and wait_until_deleted method review
Messages (8)
msg223604 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2014-07-21 20:00
As suggested by Martin in msg170717, shutil should grow some way to block until a given file/directory is actually deleted, due to Windows' scheme of not actually deleting a file until all handles to it are closed.

This could take the form of a 'wait=False' parameter to rmtree that causes rmtree to block until the file/dir is gone (which could mean blocking indefinitely), or a new function "wait_until_deleted(name, timeout=None)".

Related issues: #15946, #7443, #19629
msg224565 - (view) Author: Vivek Balakrishnan (Vivek.Balakrishnan) * Date: 2014-08-02 13:39
Patch that adds wait parameter to shutil.rmtree.
msg224566 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-02 13:46
What if other program will create a file with same name in short time after deletion? Then rmtree() will hang in infinity loop.
msg224569 - (view) Author: Vivek Balakrishnan (Vivek.Balakrishnan) * Date: 2014-08-02 14:11
With respect to msg224566, is a default timeout a good solution?
msg224572 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-02 14:44
On Linux and some other systems there is an API which allow you to subscribe 
on notifications about file system events (in particular on deleting specified 
file). There are modules which provides Python interface to it (e.g. python-
inotify, inotifyx, pyinotify). May be there is similar API on Windows?
msg224592 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-08-02 22:01
Windows has FindFirstChangeNotification and FileSystemWatcher:

msg225645 - (view) Author: Sean McCully (seanmccully) * Date: 2014-08-22 05:28
Is this closer to what Zachary.Ware suggested, patch implements a wait_until_deleted method in C Api using inotify for Linux/FreeBSD.
msg348621 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-07-29 11:35
This issue is 5 years old and has 2 patches: it's far from being "newcomer friendly", I remove the "Easy" label.
Date User Action Args
2022-04-11 14:58:06adminsetgithub: 66223
2019-07-29 11:35:02vstinnersetnosy: + vstinner
messages: + msg348621
2014-08-22 05:28:57seanmccullysetfiles: + issue22024.patch
nosy: + seanmccully
messages: + msg225645

2014-08-02 22:01:28rhettingersetnosy: + rhettinger
messages: + msg224592
2014-08-02 14:44:49serhiy.storchakasetmessages: + msg224572
2014-08-02 14:11:35Vivek.Balakrishnansetmessages: + msg224569
2014-08-02 13:52:53ezio.melottisetnosy: + loewis, ezio.melotti
2014-08-02 13:46:17serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg224566
2014-08-02 13:39:15Vivek.Balakrishnansetfiles: + shutil_wait.patch

nosy: + Vivek.Balakrishnan
messages: + msg224565

keywords: + patch
2014-07-21 20:28:17jklothsetnosy: + jkloth
2014-07-21 20:00:08zach.warecreate