ENH: trying some changes to app quit(), partly to quit in a more resilient way

and partly to allow testing to call app.quit()