I have Python 2.6 on MacOS X and multi-threaded operation. The following test code works fine and disables the application on Ctrl-C:
import threading, time, os, sys, signal
def SigIntHandler( signum, frame ) :
sys.exit( 0 )
signal.signal( signal.SIGINT, SigIntHandler )
class WorkThread( threading.Thread ) :
def run( self ) :
while True :
time.sleep( 1 )
thread = WorkThread()
thread.start()
time.sleep( 1000 )
But if I changed only one line, adding some real work to the workflow, the application will never end Ctrl-C:
import threading, time, os, sys, signal
def SigIntHandler( signum, frame ) :
sys.exit( 0 )
signal.signal( signal.SIGINT, SigIntHandler )
class WorkThread( threading.Thread ) :
def run( self ) :
while True :
os.system( "svn up" )
time.sleep( 1 )
thread = WorkThread()
thread.start()
time.sleep( 1000 )
Can this be fixed, or is python not intended for use with threads?
source
share