From f4931f1172c457a2592726b6d9a8dd37ab72a1c8 Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa Date: Mon, 6 Jan 2025 14:38:36 -0600 Subject: [PATCH 1/9] check --- .github/workflows/ci_cd.yml | 2 +- tests/conftest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 584b1920b..315967e31 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -358,7 +358,7 @@ jobs: name: Embedding scripts testing and coverage runs-on: ubuntu-latest timeout-minutes: 10 - needs: [smoke-tests, revn-variations] + needs: [revn-variations] container: image: ${{ needs.revn-variations.outputs.test_container }} options: --entrypoint /bin/bash diff --git a/tests/conftest.py b/tests/conftest.py index 6b19895be..7fc00bd74 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -176,7 +176,7 @@ def mke_app_reset(request): EMBEDDED_APP.new() -_CHECK_PROCESS_RETURN_CODE = os.name == "nt" +_CHECK_PROCESS_RETURN_CODE = True # set to True if you want to see all the subprocess stdout/stderr _PRINT_SUBPROCESS_OUTPUT_TO_CONSOLE = False From 23d233812523a4f50deb003384df964da4377d13 Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa Date: Mon, 6 Jan 2025 14:50:48 -0600 Subject: [PATCH 2/9] no crash on exit for 25.1 --- .github/workflows/ci_cd.yml | 2 +- tests/conftest.py | 4 +--- tests/embedding/test_logger.py | 8 +++++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 315967e31..584b1920b 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -358,7 +358,7 @@ jobs: name: Embedding scripts testing and coverage runs-on: ubuntu-latest timeout-minutes: 10 - needs: [revn-variations] + needs: [smoke-tests, revn-variations] container: image: ${{ needs.revn-variations.outputs.test_container }} options: --entrypoint /bin/bash diff --git a/tests/conftest.py b/tests/conftest.py index 7fc00bd74..be8cafc65 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -176,8 +176,6 @@ def mke_app_reset(request): EMBEDDED_APP.new() -_CHECK_PROCESS_RETURN_CODE = True - # set to True if you want to see all the subprocess stdout/stderr _PRINT_SUBPROCESS_OUTPUT_TO_CONSOLE = False @@ -186,7 +184,7 @@ def mke_app_reset(request): def run_subprocess(): def func(args, env=None, check: bool = None): if check is None: - check = _CHECK_PROCESS_RETURN_CODE + check = True process, output = ansys.mechanical.core.run._run( args, env, check, _PRINT_SUBPROCESS_OUTPUT_TO_CONSOLE ) diff --git a/tests/embedding/test_logger.py b/tests/embedding/test_logger.py index 76242b671..c0ef1435f 100644 --- a/tests/embedding/test_logger.py +++ b/tests/embedding/test_logger.py @@ -57,14 +57,16 @@ def _run_embedding_log_test( embedded_py = os.path.join(rootdir, "tests", "scripts", "embedding_log_test.py") subprocess_pass_expected = pass_expected - if pass_expected == True and os.name != "nt" and int(version) < 251: - subprocess_pass_expected = False + if pass_expected == True: + if os.name != "nt" and int(version) < 251: + subprocess_pass_expected = False - process, stdout, stderr = run_subprocess( + _, stdout, stderr = run_subprocess( [sys.executable, embedded_py, version, testname], _get_env_without_logging_variables(), subprocess_pass_expected, ) + if not subprocess_pass_expected: stdout = stdout.decode() _assert_success(stdout, pass_expected) From d8d51b2bb31c7e7b070c38d60321e035b70acdf7 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Mon, 6 Jan 2025 20:54:50 +0000 Subject: [PATCH 3/9] chore: adding changelog file 1026.fixed.md [dependabot-skip] --- doc/changelog.d/1026.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/1026.fixed.md diff --git a/doc/changelog.d/1026.fixed.md b/doc/changelog.d/1026.fixed.md new file mode 100644 index 000000000..7996cc7e0 --- /dev/null +++ b/doc/changelog.d/1026.fixed.md @@ -0,0 +1 @@ +Process return code \ No newline at end of file From f433b62d1eec9ca7dcb6ca390e55fb1a684a7c19 Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa Date: Tue, 7 Jan 2025 20:30:59 +0000 Subject: [PATCH 4/9] fix background initialization sequence --- src/ansys/mechanical/core/embedding/app.py | 2 ++ .../mechanical/core/embedding/background.py | 5 +++-- .../mechanical/core/embedding/initializer.py | 19 +++++++++---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/ansys/mechanical/core/embedding/app.py b/src/ansys/mechanical/core/embedding/app.py index 43d16cd83..126232b5f 100644 --- a/src/ansys/mechanical/core/embedding/app.py +++ b/src/ansys/mechanical/core/embedding/app.py @@ -62,9 +62,11 @@ def _get_default_addin_configuration() -> AddinConfiguration: def _dispose_embedded_app(instances): # pragma: nocover + print("CALLING DISPOSE EMBEDDED APP") if len(instances) > 0: instance = instances[0] instance._dispose() + print("DISPOSED!") def _cleanup_private_appdata(profile: UniqueUserProfile): diff --git a/src/ansys/mechanical/core/embedding/background.py b/src/ansys/mechanical/core/embedding/background.py index d32f31636..4b80d3011 100644 --- a/src/ansys/mechanical/core/embedding/background.py +++ b/src/ansys/mechanical/core/embedding/background.py @@ -30,12 +30,12 @@ import ansys.mechanical.core as mech from ansys.mechanical.core.embedding.poster import Poster import ansys.mechanical.core.embedding.utils as utils +from ansys.mechanical.core.embedding import initializer def _exit(background_app: "BackgroundApp"): """Stop the thread serving the Background App.""" background_app.stop() - atexit.unregister(_exit) class BackgroundApp: @@ -50,6 +50,7 @@ class BackgroundApp: def __init__(self, **kwargs): """Construct an instance of BackgroundApp.""" if BackgroundApp.__app_thread is None: + initializer.initialize(kwargs.get("version")) BackgroundApp.__app_thread = threading.Thread( target=self._start_app, kwargs=kwargs, daemon=True ) @@ -67,7 +68,6 @@ def new(): self.post(new) - atexit.register(_exit, self) @property def app(self) -> mech.App: @@ -96,6 +96,7 @@ def stop(self) -> None: def _start_app(self, **kwargs) -> None: BackgroundApp.__app = mech.App(**kwargs) BackgroundApp.__poster = BackgroundApp.__app.poster + atexit.register(_exit, self) while True: if BackgroundApp.__stop_signaled: break diff --git a/src/ansys/mechanical/core/embedding/initializer.py b/src/ansys/mechanical/core/embedding/initializer.py index fdf4d930f..3bb3d200d 100644 --- a/src/ansys/mechanical/core/embedding/initializer.py +++ b/src/ansys/mechanical/core/embedding/initializer.py @@ -162,24 +162,22 @@ def __check_loaded_libs(version: int = None): # pragma: no cover def initialize(version: int = None): """Initialize Mechanical embedding.""" - __check_python_interpreter_architecture() # blocks 32 bit python - __check_for_mechanical_env() # checks for mechanical-env in linux embedding - global INITIALIZED_VERSION + if version is None: + version = _get_latest_default_version() + + version = __check_for_supported_version(version=version) + if INITIALIZED_VERSION is not None: if INITIALIZED_VERSION != version: raise ValueError( f"Initialized version {INITIALIZED_VERSION} " f"does not match the expected version {version}." ) - return + return INITIALIZED_VERSION - if version is None: - version = _get_latest_default_version() - - version = __check_for_supported_version(version=version) - - INITIALIZED_VERSION = version + __check_python_interpreter_architecture() # blocks 32 bit python + __check_for_mechanical_env() # checks for mechanical-env in linux embedding __set_environment(version) @@ -212,4 +210,5 @@ def initialize(version: int = None): # attach the resolver resolve(version) + INITIALIZED_VERSION = version return version From 441b6561bbb13cc1c9ec891ca44d2c6d2e81827d Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa Date: Tue, 7 Jan 2025 20:40:09 +0000 Subject: [PATCH 5/9] no exception for multiple instances test --- tests/embedding/test_background.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/embedding/test_background.py b/tests/embedding/test_background.py index 962edf766..7ad1d7de1 100644 --- a/tests/embedding/test_background.py +++ b/tests/embedding/test_background.py @@ -40,7 +40,7 @@ def _run_background_app_test( subprocess_pass_expected = pass_expected if pass_expected and os.name != "nt": - if int(version) < 251 or testname == "multiple_instances": + if int(version) < 251: subprocess_pass_expected = False process, stdout, stderr = run_subprocess( From d5d77eecb837fc6ac5828b350a9c253e18391d76 Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa Date: Tue, 7 Jan 2025 20:42:27 +0000 Subject: [PATCH 6/9] fix --- src/ansys/mechanical/core/embedding/app.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ansys/mechanical/core/embedding/app.py b/src/ansys/mechanical/core/embedding/app.py index 126232b5f..43d16cd83 100644 --- a/src/ansys/mechanical/core/embedding/app.py +++ b/src/ansys/mechanical/core/embedding/app.py @@ -62,11 +62,9 @@ def _get_default_addin_configuration() -> AddinConfiguration: def _dispose_embedded_app(instances): # pragma: nocover - print("CALLING DISPOSE EMBEDDED APP") if len(instances) > 0: instance = instances[0] instance._dispose() - print("DISPOSED!") def _cleanup_private_appdata(profile: UniqueUserProfile): From 0bd5a4dd2b4cbf6c9823e582af17a6ec81cbd510 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 20:44:44 +0000 Subject: [PATCH 7/9] chore: auto fixes from pre-commit hooks --- src/ansys/mechanical/core/embedding/background.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ansys/mechanical/core/embedding/background.py b/src/ansys/mechanical/core/embedding/background.py index 4b80d3011..9c2fd571f 100644 --- a/src/ansys/mechanical/core/embedding/background.py +++ b/src/ansys/mechanical/core/embedding/background.py @@ -28,9 +28,9 @@ import typing import ansys.mechanical.core as mech +from ansys.mechanical.core.embedding import initializer from ansys.mechanical.core.embedding.poster import Poster import ansys.mechanical.core.embedding.utils as utils -from ansys.mechanical.core.embedding import initializer def _exit(background_app: "BackgroundApp"): @@ -68,7 +68,6 @@ def new(): self.post(new) - @property def app(self) -> mech.App: """Get the App instance of the background thread. From d2a5f95e94d14e7997a0cdaaad9a9a71e8b0d1b7 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Tue, 7 Jan 2025 20:45:58 +0000 Subject: [PATCH 8/9] chore: adding changelog file 1030.fixed.md [dependabot-skip] --- doc/changelog.d/1030.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/1030.fixed.md diff --git a/doc/changelog.d/1030.fixed.md b/doc/changelog.d/1030.fixed.md new file mode 100644 index 000000000..7996cc7e0 --- /dev/null +++ b/doc/changelog.d/1030.fixed.md @@ -0,0 +1 @@ +Process return code \ No newline at end of file From 797d25e012b09f0b376d26db8f7cde20404f9b0f Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Tue, 7 Jan 2025 20:52:53 +0000 Subject: [PATCH 9/9] chore: adding changelog file 1030.fixed.md [dependabot-skip] --- doc/changelog.d/1030.fixed.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changelog.d/1030.fixed.md b/doc/changelog.d/1030.fixed.md index 7996cc7e0..5000d5c90 100644 --- a/doc/changelog.d/1030.fixed.md +++ b/doc/changelog.d/1030.fixed.md @@ -1 +1 @@ -Process return code \ No newline at end of file +Background App initialization \ No newline at end of file