Skip to content

Commit 50b2898

Browse files
committed
Simplify omc_process kill logic
... by dropping Python2 support
1 parent 7f4e0a9 commit 50b2898

1 file changed

Lines changed: 7 additions & 19 deletions

File tree

OMPython/__init__.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -391,25 +391,13 @@ def __del__(self):
391391
except Exception:
392392
pass
393393
self._omc_log_file.close()
394-
if sys.version_info.major >= 3:
395-
try:
396-
self._omc_process.wait(timeout=2.0)
397-
except Exception:
398-
if self._omc_process:
399-
self._omc_process.kill()
400-
else:
401-
for i in range(0, 100):
402-
time.sleep(0.02)
403-
if self._omc_process and (self._omc_process.poll() is not None):
404-
break
405-
# kill self._omc_process process if it is still running/exists
406-
if self._omc_process is not None and self._omc_process.returncode is None:
407-
logger.warning("OMC did not exit after being sent the quit() command; killing the process with pid=%s" % str(self._omc_process.pid))
408-
if sys.platform == "win32":
409-
self._omc_process.kill()
410-
self._omc_process.wait()
411-
else:
412-
os.killpg(os.getpgid(self._omc_process.pid), signal.SIGTERM)
394+
try:
395+
self._omc_process.wait(timeout=2.0)
396+
except Exception:
397+
if self._omc_process:
398+
print("OMC did not exit after being sent the quit() command; killing the process with pid={self._omc_process.pid}")
399+
if sys.platform != "win32":
400+
os.killpg(os.getpgid(self._omc_process.pid), signal.SIGTERM)
413401
self._omc_process.kill()
414402
self._omc_process.wait()
415403

0 commit comments

Comments
 (0)