Skip to content

Commit 187f86e

Browse files
authored
use sys.exit on good paths to not create zombies (#160)
* use sys.exit on good paths to not create zombies * fix syntax
1 parent d8dc6f5 commit 187f86e

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

testmodel.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,23 @@ def writeResult():
5252
fp.flush()
5353
os.fsync(fp.fileno())
5454

55-
def writeResultAndExit(exitStatus):
55+
startJob=monotonic()
56+
57+
def writeResultAndExit(exitStatus, useOsExit=False):
5658
writeResult()
5759
print("Calling exit ...")
5860
with open(errFile, 'a+') as fp:
59-
fp.write("[Calling os._exit(%s)]\n" % exitStatus)
61+
if useOsExit:
62+
msg = "[Calling os._exit(%s), Time elapsed: %s]\n"
63+
else:
64+
msg = "[Calling sys.exit(%s), Time elapsed: %s]\n"
65+
fp.write(msg % (exitStatus, monotonic()-startJob))
6066
fp.flush()
6167
sys.stdout.flush()
62-
os._exit(exitStatus)
68+
if useOsExit:
69+
os._exit(exitStatus)
70+
else:
71+
sys.exit(exitStatus)
6372

6473
def sendExpressionTimeout(omc, cmd, timeout):
6574
with open(errFile, 'a+') as fp:
@@ -108,7 +117,7 @@ def target(res):
108117
pass
109118
with open(errFile, 'a+') as fp:
110119
fp.write("Aborted the command.\n")
111-
writeResultAndExit(0)
120+
writeResultAndExit(0, True)
112121
if res[1] is None:
113122
res[1] = ""
114123
if res[1] is not None:
@@ -324,7 +333,7 @@ def loadLibraryInNewOM():
324333
execstat["parsing"]=monotonic()-start
325334
with open(errFile, 'a+') as fp:
326335
fp.write("Timeout error for cmd: %s\n%s"%(cmd,str(e)))
327-
writeResultAndExit(0)
336+
writeResultAndExit(0, True)
328337
execstat["parsing"]=monotonic()-start
329338

330339
try:
@@ -468,7 +477,7 @@ def sendExpressionOldOrNew(cmd):
468477
execstat["build"] = monotonic()-start
469478
with open(errFile, 'a+') as fp:
470479
fp.write(str(e))
471-
writeResultAndExit(0)
480+
writeResultAndExit(0, True)
472481

473482
writeResult()
474483
# Do the simulation
@@ -518,7 +527,7 @@ def sendExpressionOldOrNew(cmd):
518527
execstat["phase"] = 6
519528
except TimeoutError as e:
520529
execstat["sim"] = monotonic()-start
521-
writeResultAndExit(0)
530+
writeResultAndExit(0, True)
522531

523532
if referenceFile=="":
524533
writeResultAndExit(0)

0 commit comments

Comments
 (0)