Created
April 23, 2019 07:24
-
-
Save firstfu/76cab1cc65b20cc11b506643b547d34d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 信號 | |
import signal | |
import sys, os | |
import time | |
import requests | |
# ########################################################################### | |
# 常用信号类型 | |
# SIGINT 终止进程 中断进程,不可通过signal.signal()捕捉(相当于Ctrl+C) | |
# SIGTERM 终止进程 软件终止信号,可通过signal.signal()捕捉(默认信号,当os.kill()没有指明信号类型时,默认的是该信号) | |
# SIGKILL 终止进程 杀死进程,不可捕捉(相当于linux下的kill命令,windows下使用会抛出异常) | |
# SIGALRM 闹钟信号 可以通过signal.alarm()和os.kill()发送该信号,可通过signal.signal()捕捉 | |
# SIGQUIT 退出进程 和SIGTERM类似,可通过signal.signal()捕捉 | |
# ########################################################################### | |
print("The process's PID is:", os.getpid()) | |
def handle_signal(signum, frame): | |
print('signum', signum) | |
print('frame', frame) | |
# call api | |
rs = requests.get('https://www.cnblogs.com/thomson-fred/p/9502497.html') | |
print(rs.text) | |
# 退出進程 | |
# sys.exit(0) | |
# 注册信号处理程序 | |
signal.signal(signal.SIGUSR1, handle_signal) | |
signal.signal(signal.SIGUSR2, handle_signal) | |
print("The process's PID is:", os.getpid()) | |
while True: | |
print('Waiting...') | |
print(time.ctime()) | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment