scripting: protect FSM execution and tracing against self-deactivation

Signed-off-by: Ruben Smits <ruben.smits@intermodalics.eu>
Merge remote-tracking branch 'origin/self-deactivating-fsm'

Conflicts:
	tests/state_test.cpp