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 josh.r
Recipients eric.snow, gregory.p.smith, josh.r, ncoghlan, pitrou, rhettinger, serhiy.storchaka
Date 2017-09-08.18:02:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1504893766.21.0.44992991501.issue31356@psf.upfronthosting.co.za>
In-reply-to
Content
I'd be -1 on this without a demonstrated broad need for this in at least some context outside of microbenchmarking utilities (which presumably have already implemented similar stuff).

If a minimum bar for applicability isn't applied, we'll end up with dozens of these special purpose managers justified by the last limited applicability one. Stuff like contextlib.closing is justifiable (though I wish it allowed you to replace the method name called, so it could call terminate, kill, release, what-have-you) since cleanup close is so common, but disabling and reenabling gc is usually for timing purposes, and there aren't *that* many tools that need it.

It doesn't seem all that useful for real time purposes either; sure, it disables gc, but it doesn't disable other forms of implicit non-local code execution that are surprisingly hard to predict (e.g. object destruction, including __del__, for non-cyclic cases is going to depend on whether the stuff being decref-ed is still owned outside the block). Disabling GC means a lot in Java, because *all* cleanup is GC; in Python, it's just cycle collection, so you're not giving much in the way of guarantees, as the code in question has to be written with a *lot* of assumptions that Python usually can't support (it's hardly a realtime language).

Seems like if you want a speed up and reliability for this case (and all other context managers intended to be low overhead), it would be better to move parts of contextlib to the C layer (e.g. contextmanager and the classes it's implemented in terms of), so the simple and correct throwaway implementations for arbitrary custom use cases are fast enough; atomicity clearly doesn't actually matter here (it can't be made atomic in any meaningful sense given the lack of thread safety), so any real problem with the provided implementations (assuming they had try/finally added to make them robust) is overhead, not atomicity; the code posted so far would be fine (after adding try/finally) without the speed issues.
History
Date User Action Args
2017-09-08 18:02:46josh.rsetrecipients: + josh.r, rhettinger, gregory.p.smith, ncoghlan, pitrou, eric.snow, serhiy.storchaka
2017-09-08 18:02:46josh.rsetmessageid: <1504893766.21.0.44992991501.issue31356@psf.upfronthosting.co.za>
2017-09-08 18:02:46josh.rlinkissue31356 messages
2017-09-08 18:02:46josh.rcreate