Use the msgbus
There is a relatively new and mostly undocumented feature of blender that fires a callback when a property is changed. Check if your version has this feature in python console.
>>> bpy.msgbus
<module 'msgbus'>
Related
https://developer.blender.org/P563
Origins to the down of the object by default
How to get an event when an object is selected?
For this case (IMO) can substitute context.scene.render.engine
for context.engine
>>> C.engine
'BLENDER_EEVEE'
>>> C.scene.render.engine
'BLENDER_EEVEE'
>>> C.scene.render
bpy.data.scenes['Scene'].render
>>> type(C.scene.render)
<class 'bpy.types.RenderSettings'>

Use msgbus to invoke a callback whenever the "engine
" property of bpy.types.RenderSettings
is altered.
import bpy
handle = object()
subscribe_to = bpy.types.RenderSettings, "engine"
def notify_test(context):
print("Notify changed!", context.scene.render.engine)
bpy.msgbus.subscribe_rna(
key=subscribe_to,
owner=handle,
args=(bpy.context,),
notify=notify_test,
)
bpy.msgbus.publish_rna(key=subscribe_to)
Note using bpy.types.Context
, "engine" does not work.
For versions without msgbus
Can use a depsgraph_update_post
(or prior scene_update_post
) handler.
import bpy
engine = bpy.context.scene.render.engine
def engine_change(scene):
global engine
if scene.render.engine != engine:
engine = scene.render.engine
print("changed", engine)
if hasattr(bpy.app.handlers, "scene_update_post"):
handler = bpy.app.handlers.scene_update_post
else:
handler = bpy.app.handlers.depsgraph_update_post
handler.append(engine_change)
msgbus
might be an option: blender.stackexchange.com/a/150881/31447 $\endgroup$