Skip to content

Commit

Permalink
use sys.exit on good paths to not create zombies (#160)
Browse files Browse the repository at this point in the history
* use sys.exit on good paths to not create zombies

* fix syntax
  • Loading branch information
adrpo authored Nov 6, 2024
1 parent d8dc6f5 commit 187f86e
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions testmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,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:
Expand Down Expand Up @@ -108,7 +117,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:
Expand Down Expand Up @@ -324,7 +333,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:
Expand Down Expand Up @@ -468,7 +477,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
Expand Down Expand Up @@ -518,7 +527,7 @@ def sendExpressionOldOrNew(cmd):
execstat["phase"] = 6
except TimeoutError as e:
execstat["sim"] = monotonic()-start
writeResultAndExit(0)
writeResultAndExit(0, True)

if referenceFile=="":
writeResultAndExit(0)
Expand Down

0 comments on commit 187f86e

Please sign in to comment.