Smart stop python implemenation