Tried this code, but it seems have some issue, can't figure it out (need your help):
import bpy
def my_handler(scene):
#print("Active object:", scene.objects.active.name)
print("Active object:", bpy.context.view_layer.objects.active.name)
#bpy.app.handlers.scene_update_post.append(my_handler)
bpy.app.handlers.depsgraph_update_post.append(my_handler)
the old original code is commented.