我写了一个程序来捕获系统信号“ ctr + z”并通过一个函数进行处理。句柄函数之后的代码是raw_input()函数。我发现在信号捕获处理之后,直到按下“ enter”键,raw_input()函数的输入提示才会出现。有什么问题吗?
我的代码:
import signal
import re
import os
import readline
import shareApi
def handler(signum, frame): # ctr + z signal is 20
if signum == 20:
path = '/usr/local/tmpConfigFile/signal.data'
shareApi.writeStringToFile(path, str(signum))
def main():
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGTSTP, handler)
prompt = "$"
while True:
path = '/usr/local/vSw/tmpConfigFile/signal.data'
if os.path.exists(path):
signum = vSwRouterShareApi.readFileToString(path)
if signum == "20":
prompt = "#"
os.system("/bin/rm -f " + path)
os.write(0,"^Z\n")
try:
cmdstr = raw_input(promot) # label
print cmdstr
except:
print ""
continue
"""
出什么问题了?如何解决?