Home > Backend Development > Python Tutorial > Detailed explanation of Python signals

Detailed explanation of Python signals

高洛峰
Release: 2017-03-17 16:55:40
Original
1585 people have browsed it

The concept of signal

Signal (signal) - The method of communication between processes is a software interrupt. Once a process receives a signal, it interrupts the original program execution flow to handle the signal.

Several common signals:

SIGINT Terminate process Interrupt process (control+c)

SIGQUIT Exit process

SIGTERM Terminate process Software termination signal (default Signal)

SIGKILL Terminate process Kill process

SIGALRM Alarm signal

For example, when pressing control+c to terminate the process, do Some processing, the code is as follows:

import signal

def fun(sig, stack_frame):
 print 'eixt %d, %s' % (sig, stack_frame)
Exit(1)

signal.signal(signal.SIGINT, fun)

signal.signal(signal.SIGINT, fun) is used to register Semaphore processingFunction,

The first parameter is the semaphore, and the second parameter can be passed to a function.

This function has two parameters by default, The first parameter sig represents the received semaphore, and the second stack_frame can be understood as the call stack that generates the interrupt semaphore sig.


The above is the detailed content of Detailed explanation of Python signals. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template