From 3b70dc928b318f2812360a5c5cbd945879b7c3a9 Mon Sep 17 00:00:00 2001 From: gmega Date: Thu, 5 Dec 2024 16:30:15 -0300 Subject: [PATCH] proper fix to race condition --- benchmarks/deluge/deluge_node.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/benchmarks/deluge/deluge_node.py b/benchmarks/deluge/deluge_node.py index 631b466..9276aa5 100644 --- a/benchmarks/deluge/deluge_node.py +++ b/benchmarks/deluge/deluge_node.py @@ -68,10 +68,14 @@ class DelugeNode(SharedFSNode[Torrent, DelugeMeta], ExperimentComponent): raise Exception(f'There were errors removing torrents: {errors}') # Wipe download folder to get rid of files that got uploaded but failed - # seeding or deletes. Check first or it may race with the remove_torrents - # operation above. - if self.downloads_root.exists(): + # seeding or deletes. + try: shutil.rmtree(self.downloads_root) + except FileNotFoundError: + # If the call to remove_torrents succeeds, this might happen. Checking + # for existence won't protect you as the client might still delete the + # folder after your check, so this is the only sane way to do it. + pass self._init_folders()