You can make the thread a daemon thread by setting the thread object's .daemon property to True. This will stop it from keeping the process alive, but it can make teardown ugly so you can get race conditions when shutting down which lead to exceptions. This may not be particularly problematic, and the angler and betta branches in POX did this in some cases. In carp, I've gone through and un-daemonized most or all of the threads.
You can just read POX code which uses threads to see how I did it (grep the code for Thread). Exactly what you can/should do depends on what your thread is doing. One minimal way is just to have your thread occasionally poll core.running. If it's False, POX is shutting down and you should exit the thread. If you want to be more responsive, you can do something like what pcap_switch does. It has a thread which blocks waiting on a queue. The component handles the core.GoingDownEvent -- when it happens, it pushes a None onto the queue. The worker thread wakes up, reads the None from the queue, and takes it as a sign to quit. -- Murphy On Jun 28, 2013, at 3:04 PM, Silvia Fichera wrote: > Hello, > I let the controller spawn a thread to listen to a socket. When I stop the > controller with CTRL-C the thread keeps running till I kill it. > Is there a function handler of CTRL-C signal that I can use to terminate > correctly the thread? > > -- > Silvia Fichera
