Skip to content

Commit 231b03c

Browse files
authored
Merge pull request Monika-After-Story#10037 from dreamscached/bugfix/singleton-racecond
Fix WindowsError/OSError in singleton
2 parents 32aa0b2 + 8ff0681 commit 231b03c

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)