file_manager: delete file trees in another thread

On slower platforms it is possible for this to take time and block the event loop.   Run shutil.rmtree in another thread to prevent this from occuring.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2021-04-22 08:46:08 -04:00 committed by Eric Callahan
parent 55941b106b
commit d46f04de0b
1 changed files with 7 additions and 1 deletions

View File

@ -201,7 +201,13 @@ class FileManager:
# Make sure that the directory does not contain a file
# loaded by the virtual_sdcard
await self._handle_operation_check(dir_path)
shutil.rmtree(dir_path)
ioloop = IOLoop.current()
self.notify_sync_lock = NotifySyncLock(dir_path)
with ThreadPoolExecutor(max_workers=1) as tpe:
await ioloop.run_in_executor(
tpe, shutil.rmtree, dir_path)
await self.notify_sync_lock.wait(30.)
self.notify_sync_lock = None
else:
try:
os.rmdir(dir_path)