Reputation: 1042
The topic basically tells what I want to to.
I read the documentation, which tells me how to handle signals but not how I can do signalling by myself.
Thanks!
Upvotes: 18
Views: 20296
Reputation: 10760
Just proposing a different method, if its on windows:
import ctypes
ucrtbase = ctypes.CDLL('ucrtbase')
c_raise = ucrtbase['raise']
c_raise(some_signal)
some_signal
can be any signal num, eg signal.SIGINT
.
Upvotes: 3
Reputation: 4505
Directly with the signal
package (new in version 3.8). For instance:
import signal
signal.raise_signal( signal.SIGINT )
Reference: https://docs.python.org/3/library/signal.html#signal.raise_signal
Upvotes: 14
Reputation: 38044
You can use the os.kill
method. Since Python 2.7 it should work (did not test it myself) on both Unix and Windows, although it needs to be called with different parameters:
import os, signal
os.kill(pid, signal.SIGHUP) # Unix version only...
Upvotes: 13