Skip to content

Commit b3872ff

Browse files
committed
fix: use __terminateProcess for executePythonFunction
1 parent 8e5916d commit b3872ff

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/DIRAC/Core/Utilities/Subprocess.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,6 @@ def pythonCall(self, function, *stArgs, **stKeyArgs):
320320
if pid == 0:
321321
os.close(readFD)
322322
self.__executePythonFunction(function, writeFD, *stArgs, **stKeyArgs)
323-
# FIXME: the close it is done at __executePythonFunction, do we need it here?
324-
os.close(writeFD)
325323
else:
326324
os.close(writeFD)
327325
readSeq = self.__selectFD([readFD])
@@ -330,14 +328,13 @@ def pythonCall(self, function, *stArgs, **stKeyArgs):
330328
try:
331329
if len(readSeq) == 0:
332330
self.log.debug("Timeout limit reached for pythonCall", function.__name__)
333-
self.__terminateProcess(psutil.Process(pid))
334-
335-
# HACK to avoid python bug
336-
# self.wait()
337-
retries = 10000
338-
while os.waitpid(pid, 0) == -1 and retries > 0:
339-
time.sleep(0.001)
340-
retries -= 1
331+
gone, alive = self.__terminateProcess(psutil.Process(pid))
332+
if alive:
333+
for p in alive:
334+
try:
335+
p.kill()
336+
except psutil.NoSuchProcess:
337+
continue
341338

342339
return S_ERROR('%d seconds timeout for "%s" call' % (self.timeout, function.__name__))
343340
elif readSeq[0] == readFD:

0 commit comments

Comments
 (0)