From e817472ccdabe571bfb4b51661774695f6c2fb5c Mon Sep 17 00:00:00 2001 From: buthed010203 Date: Sat, 20 May 2023 12:00:38 -0400 Subject: [PATCH 1/3] Potential fix for windows crashing on RemoveOrphaned --- modules/core/remove_orphaned.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/core/remove_orphaned.py b/modules/core/remove_orphaned.py index 030ee3b..202bec6 100644 --- a/modules/core/remove_orphaned.py +++ b/modules/core/remove_orphaned.py @@ -7,7 +7,6 @@ from multiprocessing import Pool from modules import util logger = util.logger -_config = None class RemoveOrphaned: @@ -23,7 +22,7 @@ class RemoveOrphaned: global _config _config = self.config - self.pool = Pool(processes=max(cpu_count() - 1, 1)) + self.pool = Pool(processes=max(cpu_count() - 1, 1), initializer=init_pool, initargs=(self.config,)) self.rem_orphaned() self.cleanup_pool() @@ -106,6 +105,10 @@ class RemoveOrphaned: self.pool.join() +def init_pool(conf): + global _config + _config = conf + def get_full_path_of_torrent_files(torrent_files, save_path): fullpath_torrent_files = [] for file in torrent_files: @@ -115,7 +118,6 @@ def get_full_path_of_torrent_files(torrent_files, save_path): fullpath_torrent_files.append(fullpath) return fullpath_torrent_files - def move_orphan(file): src = file.replace(_config.root_dir, _config.remote_dir) # Could be optimized to only run when root != remote dest = os.path.join(_config.orphaned_dir, file.replace(_config.root_dir, "")) From e295bdbf4657ba4b7b7843e34b48fb16d32c982b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 20 May 2023 16:02:06 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- modules/core/remove_orphaned.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/core/remove_orphaned.py b/modules/core/remove_orphaned.py index 202bec6..5a80754 100644 --- a/modules/core/remove_orphaned.py +++ b/modules/core/remove_orphaned.py @@ -109,6 +109,7 @@ def init_pool(conf): global _config _config = conf + def get_full_path_of_torrent_files(torrent_files, save_path): fullpath_torrent_files = [] for file in torrent_files: @@ -118,6 +119,7 @@ def get_full_path_of_torrent_files(torrent_files, save_path): fullpath_torrent_files.append(fullpath) return fullpath_torrent_files + def move_orphan(file): src = file.replace(_config.root_dir, _config.remote_dir) # Could be optimized to only run when root != remote dest = os.path.join(_config.orphaned_dir, file.replace(_config.root_dir, "")) From 2c24abbcdf1c48caf316880a6170d7af141b4b5e Mon Sep 17 00:00:00 2001 From: buthed010203 Date: Sat, 20 May 2023 12:03:31 -0400 Subject: [PATCH 3/3] Remove redundant code --- modules/core/remove_orphaned.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/core/remove_orphaned.py b/modules/core/remove_orphaned.py index 5a80754..fdfd99e 100644 --- a/modules/core/remove_orphaned.py +++ b/modules/core/remove_orphaned.py @@ -20,8 +20,6 @@ class RemoveOrphaned: self.root_dir = qbit_manager.config.root_dir self.orphaned_dir = qbit_manager.config.orphaned_dir - global _config - _config = self.config self.pool = Pool(processes=max(cpu_count() - 1, 1), initializer=init_pool, initargs=(self.config,)) self.rem_orphaned() self.cleanup_pool()