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 kristjan.jonsson
Recipients BreamoreBoy, ajaksu2, benjamin.peterson, dcjim, elachuni, gvanrossum, jon, kristjan.jonsson, mark.dickinson, pitrou, qelan, tseaver, vdupras, vstinner
Date 2013-11-19.09:51:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1384854663.74.0.917361386967.issue7105@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2013-11-19 09:51:03kristjan.jonssonsetrecipients: + kristjan.jonsson, gvanrossum, dcjim, tseaver, mark.dickinson, pitrou, vstinner, ajaksu2, jon, benjamin.peterson, vdupras, elachuni, BreamoreBoy, qelan
2013-11-19 09:51:03kristjan.jonssonsetmessageid: <1384854663.74.0.917361386967.issue7105@psf.upfronthosting.co.za>
2013-11-19 09:51:03kristjan.jonssonlinkissue7105 messages
2013-11-19 09:51:03kristjan.jonssoncreate