This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Mark.Shannon, deleted0524, erik.bray, gregory.p.smith, jdemeyer, ncoghlan, njs, rhettinger, ryanhiebert, serhiy.storchaka, xgdomingo, yselivanov
Date 2019-09-14.23:54:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1568505265.18.0.607944397617.issue29988@roundup.psfhosted.org>
In-reply-to
Content
It's also not unique to with statements - it applies to all finally clauses. The longstanding workaround when deterministic cleanup is absolutely critical has been to run the "real" application in a subthread, and devote the main thread to gracefully terminating the subthread when requested.

When cleanup is critical, but doing it in a deterministic order is less so, __del__ methods are often used to fill the gap (although they too can be interrupted by a subsequent Ctrl-C).

I also realized that allowing infinite loops in cleanup code to ignore Ctrl-C may actually be a tolerable outcome: in the worst case, users can still escalate to Ctrl-Break/kill -9/Force stop/etc and pull the entire OS process out from under the interpreter. It's not good, but may be worth it in order to better handle users pressing Ctrl-C multiple times.
History
Date User Action Args
2019-09-14 23:54:25ncoghlansetrecipients: + ncoghlan, rhettinger, gregory.p.smith, njs, Mark.Shannon, erik.bray, serhiy.storchaka, jdemeyer, yselivanov, deleted0524, ryanhiebert, xgdomingo
2019-09-14 23:54:25ncoghlansetmessageid: <1568505265.18.0.607944397617.issue29988@roundup.psfhosted.org>
2019-09-14 23:54:25ncoghlanlinkissue29988 messages
2019-09-14 23:54:24ncoghlancreate