Manual autoreload for logout

When serving my app, I have a specific error that I handle and kick the user out to the Logout page so I can guide him back with new credentials. It worked fine until I had to remove --autoreload from the serving command line. How do you think I can mimic the same behavior programmatically, so I can keep the code intact?
Problem is when this except code block is executed, the code keeps running where things need to be halted to the logout page. In other words, I want this block of code to take force user out and take him to the logout page and halt there.