Running after python script

Hi!

i have prepared a python script which lets me control the robot via some external buttons. Unfortunately, after executing my python code, the robot enters in a running state and not on normal state.
This leads to many disadvantages: for example, if i use the external teach mode, once i have enabled/ disabled it for one time, the robot exits this running mode and i am not able to enable the teach mode anymore.

Has someone has a similar problem?

in order to establish the connection, i use the RTDE interface

Thank you for your cooperation