因此,我設計了一個程序,該程序在計算機上運行,查找困擾我們的文件的特定方面,並在標誌通過時刪除文件。不幸的是,該程序似乎幾乎是隨機關閉/崩潰。我幾乎隨機地說,因爲程序在刪除文件後總是退出,但它通常會在成功後保持不變。Python程序崩潰
我已經運行了一個並行Python程序,它在相同的時間間隔內向上計數,但除此之外別無其他。該程序不會崩潰/退出,並保持打開狀態。
是否可能存在R/W訪問問題?我以管理員身份運行程序,所以我不確定爲什麼會這樣。
下面的代碼:
import glob
import os
import time
import stat
#logging
import logging
logging.basicConfig(filename='disabledBots.log')
import datetime
runTimes = 0
currentPhp = 0
output = 0
output2 = 0
while runTimes >= 0:
#Cycles through .php files
openedProg = glob.glob('*.php')
openedProg = openedProg[currentPhp:currentPhp+1]
progInput = ''.join(openedProg)
if progInput != '':
theBot = open(progInput,'r')
#Singles out "$output" on this particular line and closes the process
readLines = theBot.readlines()
wholeLine = (readLines[-4])
output = wholeLine[4:11]
#Singles out "set_time_limit(0)"
wholeLine2 = (readLines[0])
output2 = wholeLine2[6:23]
theBot.close()
if progInput == '':
currentPhp = -1
#Kills the program if it matches the code
currentTime = datetime.datetime.now()
if output == '$output':
os.chmod(progInput, stat.S_IWRITE)
os.remove(progInput)
logging.warning(str(currentTime) +' ' + progInput + ' has been deleted. Please search for a faux httpd.exe process and kill it.')
currentPhp = 0
if output2 == 'set_time_limit(0)':
os.chmod(progInput, stat.S_IWRITE)
os.remove(progInput)
logging.warning(str(currentTime) +' ' + progInput + ' has been deleted. Please search for a faux httpd.exe process and kill it.')
currentPhp = 0
else:
currentPhp = currentPhp + 1
time.sleep(30)
#Prints the number of cycles
runTimes = runTimes + 1
logging.warning((str(currentTime) + ' botKiller2.0 has scanned '+ str(runTimes) + ' times.'))
print('botKiller3.0 has scanned ' + str(runTimes) + ' times.')
當它失敗時,它是否在os.remove之後的日誌中記錄消息? – Mark
Python程序通常會在stderr上產生異常追溯,如果它們崩潰的話。你看到什麼樣的錯誤? – larsks
尚未設置錯誤消息日誌記錄。什麼是添加它的好方法? – user1698693