Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit bd3c899

Browse files
committed
30671: fix race condition in PSage deconstructor
1 parent 468f238 commit bd3c899

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/sage/interfaces/psage.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,21 @@ def __del__(self):
113113
114114
sage: PSage().__del__()
115115
"""
116-
if os.path.exists(self.__tmp_dir):
117-
for x in os.listdir(self.__tmp_dir):
118-
os.remove(os.path.join(self.__tmp_dir, x))
116+
try:
117+
files = os.listdir(self.__tmp_dir)
118+
except OSError:
119+
pass
120+
else:
121+
for x in files:
122+
try:
123+
os.remove(os.path.join(self.__tmp_dir, x))
124+
except OSError:
125+
pass
126+
try:
119127
os.removedirs(self.__tmp_dir)
128+
except OSError:
129+
pass
130+
120131
if not (self._expect is None):
121132
cmd = 'kill -9 %s'%self._expect.pid
122133
os.system(cmd)

0 commit comments

Comments
 (0)