@@ -163,6 +163,26 @@ def __str__(self):
163163 return repr (self .message )
164164
165165
166+ def isTrackerEnabled ():
167+ return 'TRACKER_ENABLED' in os .environ
168+
169+ untrackableExecutor = None
170+
171+ def untrackable (func ):
172+ if not isTrackerEnabled ():
173+ return func
174+
175+ global untrackableExecutor
176+ if not untrackableExecutor :
177+ untrackableExecutor = concurrent .futures .ThreadPoolExecutor (max_workers = 1 )
178+
179+ def executeNotInMainThread (* args , ** kwargs ):
180+ global untrackableExecutor
181+ future = untrackableExecutor .submit (func , * args , ** kwargs )
182+ return future .result ()
183+
184+ return executeNotInMainThread
185+
166186class Manifest (object ):
167187 def __init__ (self , entries = None ):
168188 if entries is None :
@@ -203,6 +223,7 @@ def setManifest(self, manifestHash, manifest):
203223 jsonobject = {'entries' : entries }
204224 json .dump (jsonobject , outFile , sort_keys = True , indent = 2 )
205225
226+ @untrackable
206227 def getManifest (self , manifestHash ):
207228 fileName = self .manifestPath (manifestHash )
208229 if not os .path .exists (fileName ):
@@ -741,6 +762,7 @@ def __init__(self, statsFile):
741762 self ._stats = None
742763 self .lock = CacheLock .forPath (self ._statsFile )
743764
765+ @untrackable
744766 def __enter__ (self ):
745767 self ._stats = PersistentJSONDict (self ._statsFile )
746768 for k in Statistics .RESETTABLE_KEYS | Statistics .NON_RESETTABLE_KEYS :
@@ -1645,7 +1667,13 @@ def scheduleJobs(cache: Any, compiler: str, cmdLine: List[str], environment: Any
16451667
16461668 exitCode = 0
16471669 cleanupRequired = False
1648- with concurrent .futures .ThreadPoolExecutor (max_workers = jobCount (cmdLine )) as executor :
1670+
1671+ if isTrackerEnabled ():
1672+ poolExecutor = concurrent .futures .ProcessPoolExecutor
1673+ else :
1674+ poolExecutor = concurrent .futures .ThreadPoolExecutor
1675+
1676+ with poolExecutor (max_workers = min (jobCount (cmdLine ),len (objectFiles ))) as executor :
16491677 jobs = []
16501678 for (srcFile , srcLanguage ), objFile in zip (sourceFiles , objectFiles ):
16511679 jobCmdLine = baseCmdLine + [srcLanguage + srcFile ]
@@ -1770,6 +1798,7 @@ def ensureArtifactsExist(cache, cachekey, reason, objectFile, compilerResult, ex
17701798
17711799
17721800if __name__ == '__main__' :
1801+ multiprocessing .freeze_support ()
17731802 if 'CLCACHE_PROFILE' in os .environ :
17741803 INVOCATION_HASH = getStringHash (',' .join (sys .argv ))
17751804 cProfile .run ('main()' , filename = 'clcache-{}.prof' .format (INVOCATION_HASH ))
0 commit comments