tag:blogger.com,1999:blog-8540221137227899134.post4933300908887019266..comments2024-03-17T00:36:18.345-07:00Comments on A Dash of Technology: A Neat Python Hack? No, Broken CodeJosiah Carlsonhttp://www.blogger.com/profile/16662314724540946069noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-8540221137227899134.post-29184536547978937792011-07-19T00:29:06.725-07:002011-07-19T00:29:06.725-07:00No worries. All is well.No worries. All is well.rhettingerhttps://www.blogger.com/profile/12489518528561538475noreply@blogger.comtag:blogger.com,1999:blog-8540221137227899134.post-32997394692184003652011-07-18T01:46:03.413-07:002011-07-18T01:46:03.413-07:00Raymond: the bug you are referring to is unrelated...Raymond: the bug you are referring to is unrelated to the cause of why the counts aren't what they are supposed to be, or why the check interval finishes at 2 billion.<br /><br />The cause of both issues is because CPython releases the GIL regardless of the check interval when it is performing certain operations. It's not a bug, it's a concurrency feature of Python, which renders the hack as being incorrect.<br /><br />Nowhere in the post did I claim that you recommended the recipe, but that you "offered it as a neat little hack". I've removed your name and a link to your Twitter, as per your request.<br /><br />My intent was to dig into the guts of a Python recipe that happened to be incorrect and to explain why it was incorrect.<br /><br />I appreciate the personal advice you gave me years ago, never mind all of your contributions to Python and the community, and I'm sorry if I have offended you.Josiah Carlsonhttps://www.blogger.com/profile/16662314724540946069noreply@blogger.comtag:blogger.com,1999:blog-8540221137227899134.post-64641621567168531822011-07-17T23:42:54.020-07:002011-07-17T23:42:54.020-07:00I believe the problem isn't with the recipe (w...I believe the problem isn't with the recipe (which expects setcheckinterval to take effect right away, as the documented API suggests) but rather a bug in Python itself which has a fix already loaded for the next release.<br /><br />Per Misc/NEWS for Python 2.7.3:<br />"""- sys.setcheckinterval() now updates the current ticker count as well as updating the check interval, so if the user decreases the check interval, the ticker doesn't have to wind down to zero from the old starting point before the new interval takes effect. And if the user increases the interval, it makes sure the new limit takes effect right away rather have an early task switch before recognizing the new interval."""<br /><br />Also, your post suggests that I recommend this recipe. If you recall the presentation, it was a list of fun, over-the-top hacks and were definitely not recommended for production use. Please remove my name from you post. <br /><br />-- Raymond Hettinger<br /><br />P.S. checkinterval hacks have been around for a very long time. IIRC, I first heard of them from Tim Peters ten years ago.rhettingerhttps://www.blogger.com/profile/12489518528561538475noreply@blogger.comtag:blogger.com,1999:blog-8540221137227899134.post-48183117382905288322011-07-17T22:35:45.609-07:002011-07-17T22:35:45.609-07:00Anon: to what are you referring when you say "...Anon: to what are you referring when you say "Just use Python 2.7.2 and all is well."? The pattern doesn't start working with 2.7.2 (or any of the 3.x series for that matter)...Josiah Carlsonhttps://www.blogger.com/profile/16662314724540946069noreply@blogger.comtag:blogger.com,1999:blog-8540221137227899134.post-18856651425667795602011-07-17T22:32:29.339-07:002011-07-17T22:32:29.339-07:00Just use Python 2.7.2 and all is well.Just use Python 2.7.2 and all is well.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8540221137227899134.post-47205485296371394572011-07-15T00:04:58.226-07:002011-07-15T00:04:58.226-07:00Hmm, good one -- I saw this also from Raymond in a...Hmm, good one -- I saw this also from Raymond in a presento a couple months ago and took it at face value -- although I'd probably never use it in real code since it relies on what seems like awfully hacky behavior...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8540221137227899134.post-32429355350927582422011-07-14T18:41:03.009-07:002011-07-14T18:41:03.009-07:00The blog is to say "this pattern sucks, here ...The blog is to say "this pattern sucks, here is how I prove it" but if you augment it with "another blog that shows you a few correct ways to use real locks (using the "with" statement to ensure certain behaviors, alternatives like finally->release lock, mutex, etc etc), then it'll add more value to the blog.<br /><br />Also, in the beginning of the blog, if you could show how many cycles a real based lock uses vs. a lightweight sometimes-lock uses, then your reader may be more inclined to finish reading because it'll answer "why should I care about a lightweight lock, is it a 2X gain? 10X gain? 100X gain?"Anonymoushttps://www.blogger.com/profile/17102207203432835637noreply@blogger.com