I was debugging a threading problem in someone else’s code the other day, and found it difficult to get a picture of what was happening. The problem with threads, you see, is that most languages make it very easy, which tempts programmers to use them and causes no end of problems later. Instead of being easy to use, they should require intimate knowledge of Sumerian syntax, or something.
At any rate, if you have threading problems in Python, you should download the threadframe module. In conjunction with, say, some quick debugging code:
def runforever(): import threadframe, traceback, time, sys while True: print ">>>>>", time.strftime("%H:%M:%S"), ", number of threads =", \len(threadframe.dict()) time.sleep(30) for id, frame in threadframe.dict().iteritems(): print "===== [%d] %s" % (id, sys.getrefcount(frame)) traceback.print_stack(frame) print import thread thread.start_new_thread(runforever, ())… suddenly, it’s as if you have been blind but can now see again!
Comments are moderated whenever I remember that I have a blog.
There are no comments on this article.