From d46f04de0b8c40207398587b46692c50b62de9c8 Mon Sep 17 00:00:00 2001 From: Arksine Date: Thu, 22 Apr 2021 08:46:08 -0400 Subject: [PATCH] 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 --- moonraker/components/file_manager.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/moonraker/components/file_manager.py b/moonraker/components/file_manager.py index ef00759..8ed67d8 100644 --- a/moonraker/components/file_manager.py +++ b/moonraker/components/file_manager.py @@ -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)