Home > Backend Development > Python Tutorial > Python signal amount

Python signal amount

高洛峰
Release: 2016-10-19 11:42:51
Original
1163 people have browsed it

The concept of signal

Signal (signal) - The way 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                                                                                   use using using using using using using using using   out out out out out off out out out out out out out out out of ‐ in ‐ ‐ ‐SIGINT ​                                  SIGALRM alarm clock signal

For example, if you want to do some processing when pressing control+c to terminate the process, 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 the processing function of the semaphore,

the first parameter It is a semaphore. The second parameter can be passed to a function. This function has two parameters by default. The first parameter sig represents the received semaphore. The second stack_frame can be understood as the call stack that generates the interrupt semaphore sig. .

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