while True: try: lockfd = os.open(path, os.O_CREAT|os.O_WRONLY|os.O_EXCL) except OSError: time.sleep(0.1) else: os.close(lockfd) break self.locked = True
Really people, really? We silently loop until an error goes away? Really?
Ken Kinder's personal website
while True: try: lockfd = os.open(path, os.O_CREAT|os.O_WRONLY|os.O_EXCL) except OSError: time.sleep(0.1) else: os.close(lockfd) break self.locked = True
Really people, really? We silently loop until an error goes away? Really?
You can follow all the replies to this entry through the comments feed.
Hi Ken, glad to see you back blogging. I was surprised when my RSS reader popped up with new entries from you. It’s been a long time!
This lock method is pretty bad I agree. I’ve seen it in C code as well, although C programmers seem a bit more likely to check for a specific error code.
The worst/most annoying file locking bug I’ve seen is in Evolution, the email program. Their mbox update code locked the original mbox file while writing a .tmp copy with the updated contents. It then used rename() to replace the original with the updated copy. At this point, the file lock is being held on the origninal file which is now DELETED! But then their code continued on as if the mbox file was still locked.
After I figured that one out and filed a bug report they REFUSED to apply my patch to fix it because they claimed it didn’t matter, then got abusive when I asked why they were bothing to lock the file in the first place.
sigh.
Yeah, sometimes it’s astonishing how resistant Open Source developers are to bug fixes. If you see my thread on CherryPy, it has yet to be answered. And since I posted it, a new version has come out, without a fix. Now CherryPy’s session code is rendering 500 errors when the user has an invalid cookie, but writes nothing in the log file. The whole thing is making me re-evaluate my choice of CherryPy.
Also your blog has a bug in the comments feed that I am seeing in the modem chat strings Aaron wrote. It isn’t escaping the ampersands correctly, creating invalid XML.
The one here?
http://kenkinder.com/comments/feed/
It looks escaped correctly to me and Firefox parses it. What RSS reader are you using?
Oh, and yeah, I thought I would start blogging again. I gave up on writing my own web framework and am now using WordPress. It’s really a very impressive little package, especially when I throw on some useful plugins.
Even though I’m loathed to use anything in PHP.
Liferea, a Gnome RSS reader. It isn’t showing an error today so I can’t see the exact problem.