[Twisted-Python] 2 threads questions
i have a threaded daemon which occasionally hangs because of some stalling in the threadpool a- whats the best way to shut it down ? attempts to ctl-c / kill it seem to be interpreted by a random thread. the only way to kill it is a kill -9 the python threading docs said that was the expected behavior, and that it could be avoided by using signal. I figured twisted might have something in it already to handle shutting down a reactor with active threads. the threads docs for twisted are a little light. b- i'm trying to figure out the cause of the stalling in the threadpool from the status messages i'm printing, I'm seeing the main python code firing fine, but the threadpool is just stuck - nothing dispatched to it seems to clean up i wonder if it might be related to a few tickets i've seen http://twistedmatrix.com/trac/ticket/2448 http://trac.edgewall.org/ticket/3923 i'm trying to figure out a way to reliably test this. i've got a ssh manhole running via conch ( and instructions from the twisted book ) can anyone suggest a good way to test and try to debug what is going on? i'm extremely uninformed when it comes to python threads.
On Tue, 27 Mar 2007 12:03:44 -0400, Jonathan Vanasco <twisted-python@2xlp.com> wrote:
i have a threaded daemon which occasionally hangs because of some stalling in the threadpool
a- whats the best way to shut it down ? attempts to ctl-c / kill it seem to be interpreted by a random thread. the only way to kill it is a kill -9 the python threading docs said that was the expected behavior, and that it could be avoided by using signal. I figured twisted might have something in it already to handle shutting down a reactor with active threads. the threads docs for twisted are a little light.
b- i'm trying to figure out the cause of the stalling in the threadpool from the status messages i'm printing, I'm seeing the main python code firing fine, but the threadpool is just stuck - nothing dispatched to it seems to clean up i wonder if it might be related to a few tickets i've seen http://twistedmatrix.com/trac/ticket/2448 http://trac.edgewall.org/ticket/3923
i'm trying to figure out a way to reliably test this. i've got a ssh manhole running via conch ( and instructions from the twisted book ) can anyone suggest a good way to test and try to debug what is going on? i'm extremely uninformed when it comes to python threads.
Python 2.5 includes sys._current_frames() which returns a mapping from thread identifiers to the frame objects which you might be able to use to learn what is going on. You can call this from your manhole prompt when you notice the system to have hung. Jean-Paul
On Mar 27, 2007, at 12:30 PM, Jean-Paul Calderone wrote:
Python 2.5 includes sys._current_frames() which returns a mapping from thread identifiers to the frame objects which you might be able to use to learn what is going on. You can call this from your manhole prompt when you notice the system to have hung.
Great! Thanks. Still working on debugging this, but for other people who need to jump into a manhole for something like this in the future -- the following works well. ======= import sys import traceback def formatTraceback ( frameId , frameObj ): traceback_lines= traceback.format_stack( frameObj ) if not len(traceback_lines): return print "" print "----------------------------------------------------------------------- -----------" print ">> --- %s | %s ===================================" % ( frameId , frameObj ) print "".join(traceback_lines) print "<< --- %s | %s ===================================" % ( frameId , frameObj ) print "" def printCurrentStack(): frames= sys._current_frames() for frameId in frames: frameObj= frames[frameId] formatTraceback( frameId , frameObj ) printCurrentStack() // Jonathan Vanasco | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | FindMeOn.com - The cure for Multiple Web Personality Disorder | Web Identity Management and 3D Social Networking | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | RoadSound.com - Tools For Bands, Stuff For Fans | Collaborative Online Management And Syndication Tools | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
participants (2)
-
Jean-Paul Calderone
-
Jonathan Vanasco