Using Msgbus to detect entering local view

I’m trying to use the message bus subscribe_to to run something when entering local view in the 3D Viewport. The code seems to work for everything I’ve tried under bpy.types.SpaceView3D except “local_view”.

import bpy

handle = object()

subscribe_to = bpy.types.SpaceView3D, "local_view"

def notify_test(context): 
    for area in bpy.context.screen.areas:
        if area.type == 'VIEW_3D':
            space = area.spaces[0]
            if space.local_view: #check if using local view
                print ("Local View Detected")
                
            else:
                print ("Local View not detected")

bpy.msgbus.subscribe_rna(
    key=subscribe_to,
    owner=handle,
    args=(bpy.context,),
    notify=notify_test,
)

bpy.msgbus.publish_rna(key=subscribe_to)

This works for
subscribe_to = bpy.types.SpaceView3D, “lens” or subscribe_to = bpy.types.SpaceView3D, “clip_start” for example, but local_view doesn’t work. Could someone tell me what I’m doing wrong please?

Thanks

3 Likes