4
我想運行下面的代碼使用supervisord,但它開始重新啓動第二我執行supervisord -c /etc/supervisord.conf
請指教?supervisord python腳本:退出狀態1;沒有預期的循環
import urllib2
import time
def goget():
url = "http://hitch.tv/grabs.php"
data = urllib2.urlopen(url)
grabbedpic = data.read()
with open('/root/python/tmp.txt', 'r') as tmpfile:
last=tmpfile.read().replace('\n','')
msgstr = []
u = 'http://hitch.tv/'
print last
if grabbedpic == last:
print "same pic"
else:
msgstr = u + grabbedpic
//send email with msgstr here
with open('tmp.txt', 'w') as tmpfile:
tmpfile.write(grabbedpic)
time.sleep(15)
while True:
goget()
這裏是supervisord.log
> 2014-02-19 22:44:17,993 INFO spawned: 'front' with pid 19859
> 2014-02-19 22:44:19,278 INFO exited: front (exit status 1; not
> expected) 2014-02-19 22:44:20,284 INFO spawned: 'front' with pid 19860
> 2014-02-19 22:44:21,516 INFO exited: front (exit status 1; not
> expected) 2014-02-19 22:44:23,523 INFO spawned: 'front' with pid 19862
> 2014-02-19 22:44:24,805 INFO exited: front (exit status 1; not
> expected) 2014-02-19 22:44:27,814 INFO spawned: 'front' with pid 19863
> 2014-02-19 22:44:29,004 INFO exited: front (exit status 1; not
> expected) 2014-02-19 22:44:30,006 INFO gave up: front entered FATAL
> state, too many start retries too quickly
輸出日誌從supervisord.conf
[program:front]
command=python /root/python/front.py
process_name = front
autostart = true
autorestart = true
startsecs = 10
stopwaitsecs = 30
有非零狀態可能意味着Python解釋器退出,因爲它捕獲的異常退出;通常它會在它的stderr上打印回溯,這可能在某個日誌中;也許'/ var/log/messages'?如果你無法在任何地方找到它,你應該自己發現異常並將它記錄在你能找到它的地方。 – SingleNegationElimination
我在終端連續運行了python腳本15分鐘,結果沒有錯誤。我將stdout_logfile =/etc/front.log行添加到了supervisord.conf文件中,它只是在日誌中輸出了'last'的值4次。 – phill
錯誤消息不會去標準輸出;在當前的'stdout_logfile'中使用'stderr_logfile'或'redirect_stderr'。在'/ etc'中放入日誌也不是一個好主意。那麼'/ var/log'呢? – SingleNegationElimination