I would like to know why doesn't python2.7 drop blocking operations when ctrl+c is pressed, I am unable to kill my threaded application, there are several socket waits, semaphore waits and so on. In python3 ctrl+c dropped every blocking operation and garbage-collected everything, released all the sockets and whatsoever ... Is there (I am convinced there is, I just yet don't know how) a way to acomplish this? Signal handle? Thanks guys
Asked
Active
Viewed 550 times
1 Answers
0
I guess you are launching the threads and then the main thread is waiting to join them on termination.
You should catch the exception generated by Ctrl-C in the main thread, in order to signal the spawned threads to terminate (changing a flag in each thread, for instance). In this manner, all the children thread will terminate and the main thread will complete the join call, reaching the bottom of your main.

ziu
- 2,634
- 2
- 24
- 39
-
Well actually I tried that, the app was still frozen on blocking read() method, the way to go was to set daemon=True, thanks anyway – sDoky Sep 13 '12 at 05:45
-
Be aware that with daemon threads there is a very real possibility that the daemon threads can still execute after the Python runtime has started its own tear-down process. So, if you notice strange exceptions on shutdown, it could be because of this setting. – ziu Sep 13 '12 at 10:13
-
About your read function, if you wrap it with select inside a loop controlled by an "end" flag, you end up with a non-blocking read. – ziu Sep 13 '12 at 10:32