From 8d2e53ad83ce7ed82a7d24bfb89aba9545654c94 Mon Sep 17 00:00:00 2001 From: Marcos Marado Date: Fri, 26 Feb 2021 22:50:12 +0000 Subject: [PATCH] save_plant: inelegant concurrency fix This inelegant and hackyish fix gives a randomly generated name to the temporary savefiles, so there is only a 0.1% chance of the filename being the same twice in a row. This solves the ocasional exceptions raised in save_plant, when there is more than one call still running at once, for the same user (due to slow writes). --- botany.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/botany.py b/botany.py index 46e6538..5a727a5 100755 --- a/botany.py +++ b/botany.py @@ -561,7 +561,7 @@ class DataManager(object): def save_plant(self, this_plant): # create savefile this_plant.last_time = int(time.time()) - temp_path = self.savefile_path + ".temp" + temp_path = self.savefile_path + ".temp" + str(random.randint(0,1000)) with open(temp_path, 'wb') as f: pickle.dump(this_plant, f, protocol=2) os.rename(temp_path, self.savefile_path)