Example of commonly used signal type in Python, pythonsignal

Source: Internet
Author: User

Example of commonly used signal type in Python, pythonsignal

This article focuses on the Signal in Python, as detailed below.

Common signal types

  1. SIGINT terminates the process to interrupt the process and cannot be captured through signal. signal () (equivalent to Ctrl + C)
  2. The software termination signal of the SIGTERM termination process, which can be captured through signal. signal () (default signal, which is the default signal when OS. kill () does not specify the signal type)
  3. SIGKILL terminates the process and kills the process. It cannot be captured (equivalent to the kill command in linux, which throws an exception when used in windows)
  4. The SIGALRM alarm signal can be sent through signal. alarm () and OS. kill (), which can be captured through signal. signal ().
  5. Similar to SIGTERM, a sigquit exit process can be captured through signal. signal ().

A. py

# Coding = utf8 import signal, OS, time def onsignal_term (a, B): print 'receive SIGTERM sign' def onsignal_quit (a, B ): print 'receive SIGQUIT signal 'def onsignal_alrm (a, B): print 'receive SIGALRM signal' signal. signal (signal. SIGTERM, onsignal_term) signal. signal (signal. SIGQUIT, onsignal_quit) signal. signal (signal. SIGALRM, onsignal_alrm) signal. alarm (10) while 1: print 'process id: ', OS. getpid () time. sleep (2)

B. py

Import OS, signal, time OS. kill (5097, signal. SIGTERM) time. sleep (5) # The OS does not work if the signal after the process is terminated. kill (4976, signal. SIGINT) OS. kill (5006, signal. SIGKILL) OS. kill (5071, signal. SIGQUIT) OS. kill (5097, signal. SIGALRM)

Summary

The above is all the content of the signal type instances commonly used in Python, and I hope to help you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.