执行
python /home/convScripts/gauss/handle_select.py /home/banex/src/ /home/bancs/user/devkl/test/find_sql/ banex 2&> banex.handle_select.log
一直没有返回,没有日志输出,也没有响应。非常奇怪啊。
我把参数改下, 检查另外的目录的 /home/bancs/src/ 却没有这个问题。 为什么呢?
查看 资源消耗情况:
devkl> top
top - 09:47:31 up 21 days, 23:05, 13 users, load average: 1.00, 1.00, 1.00
Tasks: 459 total, 2 running, 457 sleeping, 0 stopped, 0 zombie
%Cpu(s): 12.5 us, 0.0 sy, 0.0 ni, 87.4 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 15667.4 total, 6605.2 free, 1475.1 used, 7969.9 buff/cache
MiB Swap: 8192.0 total, 8186.9 free, 5.1 used. 14192.3 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
79629 bancs 20 0 38076 32456 9688 R 100.0 0.2 927:15.15 python
发现只有一个 python 进程, 其已经运行很久了, 可以看到是 927 分钟了, 还没有结束啊。 但是呢, 系统本身也还比较正常, 没有死机卡死之类的。没有其他任何异常。
怎么办呢? 查看日志,也没有发现问题, 也没有任何日志输出,似乎一个错误都没有。那只能把进程杀掉,重新看看效果吧。
Ctrl + C 进程杀掉, 发现有错误日志:
devkl> tail -f banex.handle_select.log
Traceback (most recent call last):
File "/home/bancs/hisun/convScripts/gauss/handle_select.py", line 314, in <module>
sqlDicts = handle()
File "/home/bancs/hisun/convScripts/gauss/handle_select.py", line 224, in handle
selectSqls = find_sql(path, newdir, system=system, ty=ext)
File "/home/bancs/hisun/convScripts/gauss/handle_select.py", line 69, in find_sql
while (len(select_line) < 7 or select_line[6] == '*') and idx < le:
KeyboardInterrupt
仔细看, 可能while (len(select_line) < 7 or select_line[6] == '*') and idx < le: 这行的问题吧。 难道是 while 死循环?
检查代码, 发现果真如此。
idx2 = idx + 1
while (len(from_line) < 7 or from_line[6] == '*') and idx < le:
idx2 = idx + 1
from_line = lines[idx2]
and idx < le: 这个地方 没有使用递增变量啊!!
哦, 其实这个错误,之前测试页出现了的,但是没有引起重视。 之前以为 死循环 就会导致系统卡死, 其实不然,特别是python 之中, 因为 它只占用一个核, 所以不影响其他进程。 其实 cpu 100% 就需要引起怀疑了。
好吧,就是这个原因! 搞定了! 下次还是认真点~