0

I want to customize a signal handler on windows, and then use os.kill in other processes to notify the signal to execute the corresponding handler. But the result is that the signal still executes the default handler.

I wrote the following test code, the same code, in the window, did not print anything. In Linux, 'hi' is printed.

import os
import signal
def sigint(*args):
    print('hi')
signal.signal(signal.SIGINT , sigint)
os.kill(os.getpid(), signal.SIGINT)

Why lead to such different results?

  • 1
    Does this answer your question? [How to handle a signal.SIGINT on a Windows OS machine?](https://stackoverflow.com/questions/35772001/how-to-handle-a-signal-sigint-on-a-windows-os-machine) – stark Aug 18 '22 at 12:01
  • I inserted the kill function from the first answer. It works when `pid == os.getpid()`. But it failed when I try to signal from one process to another, ie `pid! = os.getpid()`. If the SIGINT signal is sent at this time, `os.kill(pid, signal.CTRL_C_EVENT)` will actually be run. The error message tells me: `builtins.SystemError: returned a result with an error set`. I don't know if it's because my code is running in Python's twisted framework. – Michael Aug 19 '22 at 03:32

0 Answers0