python额外的值添加到变量中

时间:2012-05-01 17:50:53

标签: python linux debian

我正在运行在两台服务器上运行的python zabbix trapper脚本,它可以正常工作。它每30秒运行一次。这是从“ss”

读取time_wait状态的代码部分
file_log = "/tmp/tcpstate.log"
proc = open(file_log,"a")

file = "/var/log/safesquid/safesquid/performance/performance.log"
time_wait_cmd = subprocess.Popen("ss -o state time-wait | grep webcache | wc -l",shell=True,stdout=subprocess.PIPE)
ssquid_time = time_wait_cmd.communicate()[0]
proc_string = datetime.datetime.now().strftime("%d-%m-%y %H:%M:%S") + " " + "Time_WAIT: " + ssquid_time  + "\n"
proc.write(proc_string)
proc.close()

来自server1的输出:(OK)

01-05-12 17:40:50 Time_WAIT: 286
01-05-12 17:41:20 Time_WAIT: 251
01-05-12 17:41:50 Time_WAIT: 366
01-05-12 17:42:20 Time_WAIT: 335
01-05-12 17:42:50 Time_WAIT: 287
01-05-12 17:43:20 Time_WAIT: 375
01-05-12 17:43:51 Time_WAIT: 386
01-05-12 17:44:21 Time_WAIT: 383

Server2的输出:(问题)

01-05-12 17:44:03 Time_WAIT: 368
01-05-12 17:44:32 Time_WAIT: 388
01-05-12 17:45:01 Time_WAIT: 0
01-05-12 17:45:01 Time_WAIT: 339
01-05-12 17:45:31 Time_WAIT: 311
01-05-12 17:46:00 Time_WAIT: 400
01-05-12 17:46:01 Time_WAIT: 0
01-05-12 17:46:29 Time_WAIT: 411
01-05-12 17:46:58 Time_WAIT: 448

因为它每隔30秒被调用一次,我不确定为什么在Server2上它获得“0”值然后立即读取正确的值。

为什么会发生这种情况?

1 个答案:

答案 0 :(得分:0)

是否有进程接收信号?这可能导致系统调用比预期更早终止。