From c371329cc20ee4be00c6e85fabdc0d61b34bf063 Mon Sep 17 00:00:00 2001 From: Gioele Barabucci Date: Mon, 27 Feb 2023 18:12:12 +0100 Subject: [PATCH 2/2] dtrace: Use directory random directory instead of busy waiting --- dtrace.in | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/dtrace.in b/dtrace.in index 22c1a9d03..a20fb5c4a 100644 --- a/dtrace.in +++ b/dtrace.in @@ -26,6 +26,7 @@ import sys import time import atexit from shlex import split +from tempfile import mkdtemp from subprocess import call try: from pyparsing import alphas, cStyleComment, delimitedList, Group, \ @@ -36,6 +37,8 @@ try: except ImportError: HAVE_PYP = False +TEMP_DIR = None + # Common file creation methods for pyparsing and string pattern matching @@ -282,20 +285,9 @@ def mktemp_determ(sources, suffix): sha = hashlib.sha256() for source in sources: sha.update(source.encode('utf-8')) - fname = ".dtrace-temp." + sha.hexdigest()[:8] + suffix - tries = 0 - while True: - tries += 1 - if tries > 100: # if file exists due to previous crash or whatever - raise Exception("cannot create temporary file \""+fname+"\"") - try: - wxmode = 'x' if sys.version_info > (3,0) else 'wx' - fdesc = open(fname, mode=wxmode) - break - except FileExistsError: - time.sleep(0.1) # vague estimate of elapsed time for concurrent identical gcc job - pass # Try again - + fname = TEMP_DIR + "/.dtrace-temp." + sha.hexdigest()[:8] + suffix + wxmode = 'x' if sys.version_info > (3,0) else 'wx' + fdesc = open(fname, mode=wxmode) return fdesc, fname @@ -326,6 +318,7 @@ def main(): return 1 global HAVE_PYP + global TEMP_DIR i = 1 build_header = False build_source = False @@ -380,6 +373,7 @@ def main(): usage() return 1 + TEMP_DIR = mkdtemp() if s_filename != "" and use_cpp: (ignore, fname) = mktemp_determ(["use_cpp", s_filename], suffix=".d") cpp = os.environ.get("CPP", "cpp") @@ -458,6 +452,9 @@ def main(): else: print("cpp: " + s_filename) + if not keep_temps: + os.rmdir(TEMP_DIR) + return 0 if __name__ == "__main__": -- 2.39.2