Update a custom property after leaving edit-mode? I'm looking for a way to automatically run the update_length() function after editing the actual curve, this would make my curve_length property always be up to date.
import bpy

obj = bpy.context.object

bpy.types.Object.curve_length = bpy.props.FloatProperty(
    name = 'Curve Length',
    description = 'Curve Length',
    default = 0
    )

def calculate_curve_length (obj):
    curve_length = obj.data.splines[0].calc_length()
    return curve_length

def update_length()
    obj.curve_length = calculate_curve_length (obj)

update_length()
You can subscribe to changes in an objects mode.
import bpy

# Create a unique object as a handle for the subscriber.
my_handle = object()


def my_notify(a, b, c):
    print(a, b, c)

def register():
    bpy.msgbus.subscribe_rna(
        key=(bpy.types.Object, &quot;mode&quot;),
        owner=my_handle,
        # Can be anything, passed to 'notify'.
        args=(1,2,6),
        notify=my_notify,
    )

def unregister():
    # Clear on unregister.
    bpy.msgbus.clear_by_owner(my_handle)

register()
```