From 050c9b76085fea5f7f11977210478e68a196fdd4 Mon Sep 17 00:00:00 2001 From: Ivo Steinbrecher Date: Thu, 13 Jun 2024 12:02:18 +0200 Subject: [PATCH 1/3] Update pip during testing --- .github/workflows/build-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index db638db..6ebb12f 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -35,6 +35,8 @@ jobs: # Create the virtual environment python3 -m venv $PYTHON_VENV source $PYTHON_VENV/bin/activate + # Update pip + pip install --upgrade pip # Install cubitpy pip install .[CI-CD] # Print information on the python environment From 3db58f92526f3ec52c6071655111ad54a8645fb8 Mon Sep 17 00:00:00 2001 From: Ivo Steinbrecher Date: Thu, 13 Jun 2024 12:02:22 +0200 Subject: [PATCH 2/3] Remove wrongly checked in testing file --- ...st_element_types_quad_z_values_cubitpy.dat | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 tests/test_element_types_quad_z_values_cubitpy.dat diff --git a/tests/test_element_types_quad_z_values_cubitpy.dat b/tests/test_element_types_quad_z_values_cubitpy.dat deleted file mode 100644 index 650e951..0000000 --- a/tests/test_element_types_quad_z_values_cubitpy.dat +++ /dev/null @@ -1,22 +0,0 @@ - --------------------------------------------------------NODE COORDS -NODE 1 COORD 5.0000000000000000e-01 6.1232342629258393e-17 -1.0000000000000000e+00 -NODE 2 COORD 1.6666667163372040e-01 6.1232342629258393e-17 -1.0000000000000000e+00 -NODE 3 COORD 1.6666667163372040e-01 -4.6351060092292664e-34 7.5697026662207798e-18 -NODE 4 COORD 5.0000000000000000e-01 0.0000000000000000e+00 0.0000000000000000e+00 -NODE 5 COORD -1.6666667163372040e-01 6.1232342629258393e-17 -1.0000000000000000e+00 -NODE 6 COORD -1.6666667163372040e-01 -4.6351060092292664e-34 7.5697026662207798e-18 -NODE 7 COORD -5.0000000000000000e-01 6.1232342629258393e-17 -1.0000000000000000e+00 -NODE 8 COORD -5.0000000000000000e-01 0.0000000000000000e+00 0.0000000000000000e+00 -NODE 9 COORD 1.6666667163372040e-01 -6.1232342629258393e-17 1.0000000000000000e+00 -NODE 10 COORD 5.0000000000000000e-01 -6.1232342629258393e-17 1.0000000000000000e+00 -NODE 11 COORD -1.6666667163372040e-01 -6.1232342629258393e-17 1.0000000000000000e+00 -NODE 12 COORD -5.0000000000000000e-01 -6.1232342629258393e-17 1.0000000000000000e+00 -------------------------------------------------STRUCTURE ELEMENTS - 1 WALL QUAD4 1 2 3 4 MAT 1 KINEM nonlinear EAS none THICK 1.0 STRESS_STRAIN plane_stress GP 3 3 - 2 WALL QUAD4 2 5 6 3 MAT 1 KINEM nonlinear EAS none THICK 1.0 STRESS_STRAIN plane_stress GP 3 3 - 3 WALL QUAD4 5 7 8 6 MAT 1 KINEM nonlinear EAS none THICK 1.0 STRESS_STRAIN plane_stress GP 3 3 - 4 WALL QUAD4 4 3 9 10 MAT 1 KINEM nonlinear EAS none THICK 1.0 STRESS_STRAIN plane_stress GP 3 3 - 5 WALL QUAD4 3 6 11 9 MAT 1 KINEM nonlinear EAS none THICK 1.0 STRESS_STRAIN plane_stress GP 3 3 - 6 WALL QUAD4 6 8 12 11 MAT 1 KINEM nonlinear EAS none THICK 1.0 STRESS_STRAIN plane_stress GP 3 3 ----------------------------------------------------------------END From 2b2468441e6e43b3a2853c431b6ce1f71547a881 Mon Sep 17 00:00:00 2001 From: Ivo Steinbrecher Date: Thu, 13 Jun 2024 12:02:26 +0200 Subject: [PATCH 3/3] Fix runtime error at interpreter shutdown --- cubitpy/cubit_wrapper/cubit_wrapper_host.py | 31 +++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/cubitpy/cubit_wrapper/cubit_wrapper_host.py b/cubitpy/cubit_wrapper/cubit_wrapper_host.py index fe520a1..631012d 100644 --- a/cubitpy/cubit_wrapper/cubit_wrapper_host.py +++ b/cubitpy/cubit_wrapper/cubit_wrapper_host.py @@ -35,6 +35,7 @@ # Import python modules. import execnet import os +import atexit import numpy as np # Import global options. @@ -132,7 +133,14 @@ def __init__( cubit_id = self.send_and_return(["init", arguments]) self.cubit = CubitObjectMain(self, cubit_id) - def send_and_return(self, argument_list, check_number_of_channels=False): + # We need to register a function called at interpreter shutdown that ensures that the + # execnet connection is closed first. Otherwise we get a runtime error during shutdown. + def cleanup_execnet_gateway(): + self.cubit.cubit_connect.gw.exit() + + atexit.register(cleanup_execnet_gateway) + + def send_and_return(self, argument_list): """Send arguments to the python client and collect the return values. Args @@ -141,18 +149,15 @@ def send_and_return(self, argument_list, check_number_of_channels=False): First item is either a string with the action, or a cubit item id. In the second case a method will be called on the item, with the arguments stored in the second entry in argument_list. - check_number_of_channels: bool - If true it is checked if the channel still exists. This is - necessary in cases where we delete items after the connection has - been closed. """ - if check_number_of_channels: - if len(self.gw._channelfactory.channels()) == 0: - return None - - self.channel.send(argument_list) - return self.channel.receive() + # If the channel is already finalized we get a runtime error here. This happens in cases + # where we delete items after the connection has been closed. We catch this error here. + try: + self.channel.send(argument_list) + return self.channel.receive() + except: + return None def get_attribute(self, cubit_object, name): """Return the attribute 'name' of cubit_object. If the attribute is @@ -290,9 +295,7 @@ def __del__(self): """When this object is deleted, the object in the client can also be deleted. """ - self.cubit_connect.send_and_return( - ["delete", self.cubit_id], check_number_of_channels=True - ) + self.cubit_connect.send_and_return(["delete", self.cubit_id]) def __str__(self): """Return the string from the client."""