Skip to content

Commit 8ff0681

Browse files
committed
Fix WindowsError/OSError in singleton
1 parent bd44e0d commit 8ff0681

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

Monika After Story/game/python-packages/singleton.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ def __init__(self, flavor_id=""):
3636
# file already exists, we try to remove (in case previous
3737
# execution was interrupted)
3838
if os.path.exists(self.lockfile):
39-
os.unlink(self.lockfile)
39+
try:
40+
os.unlink(self.lockfile)
41+
except OSError:
42+
# Race conditions happen, make sure the file is actually deleted
43+
# Carry on with the startup if it is
44+
if os.path.exists(self.lockfile):
45+
raise
46+
4047
self.fd = os.open(self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR)
4148

4249
except OSError as e:

0 commit comments

Comments
 (0)