From deb1a057a7920d522aa32db4c08964a73be21c37 Mon Sep 17 00:00:00 2001 From: Adrian Pop Date: Wed, 6 Nov 2024 20:27:47 +0100 Subject: [PATCH 1/2] use sys.exit on good paths to not create zombies --- testmodel.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/testmodel.py b/testmodel.py index 97baede..95cce44 100755 --- a/testmodel.py +++ b/testmodel.py @@ -42,14 +42,23 @@ def writeResult(): fp.flush() os.fsync(fp.fileno()) -def writeResultAndExit(exitStatus): +startJob=monotonic() + +def writeResultAndExit(exitStatus, useOsExit=False): writeResult() print("Calling exit ...") with open(errFile, 'a+') as fp: - fp.write("[Calling os._exit(%s)]\n" % exitStatus) + if useOsExit: + msg = "[Calling os._exit(%s), Time elapsed: %s]\n" + else: + msg = "[Calling sys.exit(%s), Time elapsed: %s]\n" + fp.write(msg % (exitStatus, monotonic()-startJob) fp.flush() sys.stdout.flush() - os._exit(exitStatus) + if useOsExit: + os._exit(exitStatus) + else: + sys.exit(exitStatus) def sendExpressionTimeout(omc, cmd, timeout): with open(errFile, 'a+') as fp: @@ -98,7 +107,7 @@ def target(res): pass with open(errFile, 'a+') as fp: fp.write("Aborted the command.\n") - writeResultAndExit(0) + writeResultAndExit(0, True) if res[1] is None: res[1] = "" if res[1] is not None: @@ -314,7 +323,7 @@ def loadLibraryInNewOM(): execstat["parsing"]=monotonic()-start with open(errFile, 'a+') as fp: fp.write("Timeout error for cmd: %s\n%s"%(cmd,str(e))) - writeResultAndExit(0) + writeResultAndExit(0, True) execstat["parsing"]=monotonic()-start try: @@ -458,7 +467,7 @@ def sendExpressionOldOrNew(cmd): execstat["build"] = monotonic()-start with open(errFile, 'a+') as fp: fp.write(str(e)) - writeResultAndExit(0) + writeResultAndExit(0, True) writeResult() # Do the simulation @@ -508,7 +517,7 @@ def sendExpressionOldOrNew(cmd): execstat["phase"] = 6 except TimeoutError as e: execstat["sim"] = monotonic()-start - writeResultAndExit(0) + writeResultAndExit(0, True) if referenceFile=="": writeResultAndExit(0) From 5995ceb36112f762d82de1aaff038d96aaf5e99b Mon Sep 17 00:00:00 2001 From: Adrian Pop Date: Wed, 6 Nov 2024 20:38:04 +0100 Subject: [PATCH 2/2] fix syntax --- testmodel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testmodel.py b/testmodel.py index 95cce44..90fb6ac 100755 --- a/testmodel.py +++ b/testmodel.py @@ -52,7 +52,7 @@ def writeResultAndExit(exitStatus, useOsExit=False): msg = "[Calling os._exit(%s), Time elapsed: %s]\n" else: msg = "[Calling sys.exit(%s), Time elapsed: %s]\n" - fp.write(msg % (exitStatus, monotonic()-startJob) + fp.write(msg % (exitStatus, monotonic()-startJob)) fp.flush() sys.stdout.flush() if useOsExit: