Message203345
No matter how it sounds, it certainly looks cleaner in code.
Look at all this code, designed to work around an unexpected GC collection with various pointy bits and edge cases and special corners.
Compare to explicitly just asking GC to relent, for a bit:
def getitems(self):
with gc.disabled():
for each in self.data.items():
yield each
That's it.
While a native implementation of such a context manager would be better (faster, and could be made overriding), a simple one can be constructed thus:
@contextlib.contextmanagerd
def gc_disabled():
enabled = gc.isenabled()
gs.disable()
try:
yield
finally:
if enabled:
gc.enable()
Such global "atomic" context managers are well known to stackless programmers. It's a very common idiom when building higher level primitives (such as locks) from lower level ones.
with stackless.atomic():
do()
various()
stuff_that_does_not_like_being_interrupted()
(stackless.atomic prevents involuntary tasklet switching _and_ involuntary thread switching) |
|
Date |
User |
Action |
Args |
2013-11-19 09:51:03 | kristjan.jonsson | set | recipients:
+ kristjan.jonsson, gvanrossum, dcjim, tseaver, mark.dickinson, pitrou, vstinner, ajaksu2, jon, benjamin.peterson, vdupras, elachuni, BreamoreBoy, qelan |
2013-11-19 09:51:03 | kristjan.jonsson | set | messageid: <1384854663.74.0.917361386967.issue7105@psf.upfronthosting.co.za> |
2013-11-19 09:51:03 | kristjan.jonsson | link | issue7105 messages |
2013-11-19 09:51:03 | kristjan.jonsson | create | |
|