# pydoc > _signal

---
type: CommandReference
command: _signal
mode: pydoc
section: ""
source: pydoc3
---

## Quick Reference

- `signal(signalnum, handler)` — set the action for a signal; returns previous action
- `getsignal(signalnum)` — return current action for a signal (SIG_IGN, SIG_DFL, None, or callable)
- `alarm(time)` — schedule SIGALRM after `time` seconds
- `pause()` — wait until a signal arrives
- `setitimer(which, value, interval)` — set an interval timer; returns old (delay, interval)
- `getitimer(which)` — get current value of an interval timer
- `set_wakeup_fd(fd, *, warn_on_full_buffer=True)` — set fd written to when signal arrives
- `valid_signals()` — set of valid signal numbers on this platform

## Name

`_signal` — built-in module providing mechanisms to use signal handlers in Python.

## Synopsis

`import _signal`

This module provides functions to set signal handlers, interval timers, and manage signal delivery. It also defines signal constants (e.g., `SIGINT`, `SIGTERM`) and itimer constants (`ITIMER_REAL`, `ITIMER_VIRTUAL`, `ITIMER_PROF`).

## Functions

- `alarm(time)` — arrange for SIGALRM to arrive after `time` seconds.
- `default_int_handler()` — the default handler for SIGINT installed by Python; raises `KeyboardInterrupt`.
- `getitimer(which)` — returns current value of given itimer (one of `ITIMER_REAL`, `ITIMER_VIRTUAL`, `ITIMER_PROF`).
- `getsignal(signalnum)` — return current action for the signal. Returns: `SIG_IGN`, `SIG_DFL`, `None` (unknown), or a callable Python object.
- `pause()` — wait until a signal arrives.
- `pidfd_send_signal(pidfd, sig, siginfo, flags)` — send a signal to a process referred to by a pid file descriptor.
- `pthread_kill(thread_id, signalnum)` — send a signal to a thread.
- `pthread_sigmask(how, mask)` — fetch and/or change the signal mask of the calling thread.
- `raise_signal(signalnum)` — send a signal to the executing process.
- `set_wakeup_fd(fd, *, warn_on_full_buffer=True)` — set the fd to be written to (with the signal number) when a signal arrives. Returns previous fd or -1. The fd must be non-blocking.
- `setitimer(which, value, interval)` — set given itimer (`ITIMER_REAL`, `ITIMER_VIRTUAL`, or `ITIMER_PROF`). Timer fires after `value` seconds, then every `interval` seconds. Set `value` to zero to clear. Returns old values as tuple: `(delay, interval)`.
- `siginterrupt(sig, flag)` — change system call restart behaviour. If `flag` is False, system calls will be restarted when interrupted by signal `sig`; else they will be interrupted.
- `signal(signalnum, action)` — set the action for the given signal. `action` can be `SIG_DFL`, `SIG_IGN`, or a callable Python object. Returns previous action. **Important**: A signal handler function is called with two arguments: the signal number and the interrupted stack frame.
- `sigpending()` — examine pending signals; returns a set of signal numbers pending for delivery to the calling thread.
- `sigtimedwait(sigset, timeout)` — like `sigwaitinfo()`, but with a timeout specified in seconds (floating point).
- `sigwait(sigset)` — suspend calling thread until delivery of one of the signals in `sigset`; accepts the signal and returns the signal number.
- `sigwaitinfo(sigset)` — wait synchronously until one of the signals in `sigset` is delivered; returns a `struct_siginfo` containing information about the signal.
- `strsignal(signalnum)` — return the system description of the given signal (e.g., "Interrupt", "Segmentation fault"). Returns `None` if not recognized.
- `valid_signals()` — return a set of valid signal numbers on this platform; can be safely passed to `pthread_sigmask`.

## Constants

### Signal numbers
`SIGABRT=6`, `SIGALRM=14`, `SIGBUS=7`, `SIGCHLD=17`, `SIGCLD=17`, `SIGCONT=18`, `SIGFPE=8`, `SIGHUP=1`, `SIGILL=4`, `SIGINT=2`, `SIGIO=29`, `SIGIOT=6`, `SIGKILL=9`, `SIGPIPE=13`, `SIGPOLL=29`, `SIGPROF=27`, `SIGPWR=30`, `SIGQUIT=3`, `SIGRTMAX=64`, `SIGRTMIN=34`, `SIGSEGV=11`, `SIGSTOP=19`, `SIGSYS=31`, `SIGTERM=15`, `SIGTRAP=5`, `SIGTSTP=20`, `SIGTTIN=21`, `SIGTTOU=22`, `SIGURG=23`, `SIGUSR1=10`, `SIGUSR2=12`, `SIGVTALRM=26`, `SIGWINCH=28`, `SIGXCPU=24`, `SIGXFSZ=25`

### Signal actions
- `SIG_DFL=0` — refer to the system default handler
- `SIG_IGN=1` — ignore the signal

### Signal mask manipulation
- `SIG_BLOCK=0`, `SIG_UNBLOCK=1`, `SIG_SETMASK=2`

### Other
- `NSIG=65` — number of defined signals
- `ITIMER_REAL=0` — decrements in real time, delivers SIGALRM upon expiration
- `ITIMER_VIRTUAL=1` — decrements only when process executing, delivers SIGVTALRM
- `ITIMER_PROF=2` — decrements when process executing or system on its behalf; delivers SIGPROF; used for profiling

## See Also

- Python documentation: [signal module](https://docs.python.org/3/library/signal.html)