Optimize for none-intercative environment

prevent the infinite loop when the script is running in a
none-intercative environment.