4

I have a thread being generated from the main one which has basically an infinite loop with a system blocking function: something like:

def run(self):
    global EXIT
    while not EXIT:
        data = self.conn.recv(1024)
        ...

I have defined a signal handler for SIGINT

def sig_handler(signum, frame):
    global EXIT, threads
    if (signum == 2):#defensive
        print("Called SIGINT")
        EXIT = True

Being the signal catched by the main thread, it interrupts the main thread. However the other thread is stuck on the blocking function: is there a way to interrupt a system call blocking function in python so that exiting from this function?

I do not want to stop the process directly how SIGINT normally does but I would like just to interrupt recv so that the condition of while is not true anymore and I can do other stuff before exiting.

roschach
  • 8,390
  • 14
  • 74
  • 124
  • This may help you [https://danielkaes.wordpress.com/2009/06/04/how-to-catch-kill-events-with-python/](https://danielkaes.wordpress.com/2009/06/04/how-to-catch-kill-events-with-python/) – Valijon Jan 06 '19 at 20:11

0 Answers0