Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Commit

Permalink
clcache/__main.py__ : can retry save stats.txt
Browse files Browse the repository at this point in the history
On long compilations with a lots of hits, stats.txt can sometimes fail to be saved.
This patch allows a second try after one second.

It has been successfully tested on a 600kLoc project, where this error was frequent.

full stack trace of the error that is corrected

29>  """
29>  Traceback (most recent call last):
29>    File "c:\python36-32\lib\concurrent\futures\process.py", line 175, in _process_worker
29>      r = call_item.fn(*call_item.args, **call_item.kwargs)
29>    File "c:\python36-32\lib\site-packages\clcache\__main__.py", line 1725, in processSingleSource
29>      return processDirect(cache, objectFile, compiler, cmdLine, sourceFile)
29>    File "c:\python36-32\lib\site-packages\clcache\__main__.py", line 1755, in processDirect
29>      return processCacheHit(cache, objectFile, cachekey)
29>    File "c:\python36-32\lib\site-packages\clcache\__main__.py", line 1537, in processCacheHit
29>      stats.registerCacheHit()
29>    File "c:\python36-32\lib\site-packages\clcache\__main__.py", line 153, in untrackedFunc
29>      return func(*args, **kwargs)
29>    File "c:\python36-32\lib\site-packages\clcache\__main__.py", line 795, in __exit__
29>      self._stats.save()
29>    File "c:\python36-32\lib\site-packages\clcache\__main__.py", line 703, in save
29>      json.dump(self._dict, f, sort_keys=True, indent=4)
29>    File "c:\python36-32\lib\contextlib.py", line 88, in __exit__
29>      next(self.gen)
29>    File "c:\python36-32\lib\site-packages\clcache\__main__.py", line 162, in atomicWrite
29>      os.replace(tempFileName, fileName)
29>  PermissionError: [WinError 5] Access is denied: 'C:\\Users\\pascal\\clcache\\stats.txt.new' -> 'C:\\Users\\pascal\\clcache\\stats.txt'
29>  """
  • Loading branch information
Pascal Thomet committed Nov 19, 2018
1 parent 377c2c8 commit 78a4630
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion clcache/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import subprocess
import sys
import threading
import time

from tempfile import TemporaryFile
from typing import Any, List, Tuple, Iterator

Expand Down Expand Up @@ -750,7 +752,12 @@ def __enter__(self):

def __exit__(self, typ, value, traceback):
# Does not write to disc when unchanged
self._stats.save()
try:
self._stats.save()
except PermissionError:
printTraceStatement("self._stats.save() has failed. Trying a second time")
time.sleep(1)
self._stats.save()

def __eq__(self, other):
return type(self) is type(other) and self.__dict__ == other.__dict__
Expand Down

0 comments on commit 78a4630

Please sign in to comment.