No it works fine (OSRS at least).
It only does one attempt though. so if there's something blocking the log out (an animation, an interface, ...) then it won't do anything.
Building off what @Negrita said, your logic right now sounds like "attempt to logout when I hit stop" meaning it will only attempt it once and if it doesn't compete the task it will seem like logout doesn't work.