➜

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.

作者 kristjan.jonsson
收信人 BreamoreBoy, ajaksu2, benjamin.peterson, dcjim, elachuni, gvanrossum, jon, kristjan.jonsson, mark.dickinson, pitrou, qelan, tseaver, vdupras, vstinner
日期 2013-11-19.09:51:03
SpamBayes Score -1.0
Marked as misclassified 是
Message-id <1384854663.74.0.917361386967.issue7105@psf.upfronthosting.co.za>
In-reply-to
内容
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)
历史
日期 用户 动作 参数
2013-11-19 09:51:03kristjan.jonsson修改recipients: + kristjan.jonsson, gvanrossum, dcjim, tseaver, mark.dickinson, pitrou, vstinner, ajaksu2, jon, benjamin.peterson, vdupras, elachuni, BreamoreBoy, qelan
2013-11-19 09:51:03kristjan.jonsson修改messageid: <1384854663.74.0.917361386967.issue7105@psf.upfronthosting.co.za>
2013-11-19 09:51:03kristjan.jonsson链接issue7105 messages
2013-11-19 09:51:03kristjan.jonsson创建