2014-02-20 101 views
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 
+0

有非零狀態可能意味着Python解釋器退出,因爲它捕獲的異常退出;通常它會在它的stderr上打印回溯,這可能在某個日誌中;也許'/ var/log/messages'?如果你無法在任何地方找到它,你應該自己發現異常並將它記錄在你能找到它的地方。 – SingleNegationElimination

+0

我在終端連續運行了python腳本15分鐘,結果沒有錯誤。我將stdout_logfile =/etc/front.log行添加到了supervisord.conf文件中,它只是在日誌中輸出了'last'的值4次。 – phill

+0

錯誤消息不會去標準輸出;在當前的'stdout_logfile'中使用'stderr_logfile'或'redirect_stderr'。在'/ etc'中放入日誌也不是一個好主意。那麼'/ var/log'呢? – SingleNegationElimination

回答

1

由於eggonlegs在評論中提到,你可以通過檢查進一步探索您的日誌/var/log/supervisor/目錄。我有完全相同的問題,我發現了以下文件被創建:

celery_worker-stderr---supervisor-DEjyLf.log 

(作爲我的程序[program:front]的名稱)。

通過檢查它我發現:

File "/usr/lib/python3.4/logging/__init__.py", line 1006, in __init__ 
    StreamHandler.__init__(self, self._open()) 
    File "/usr/lib/python3.4/logging/__init__.py", line 1030, in _open 
    return open(self.baseFilename, self.mode, encoding=self.encoding) 
PermissionError: [Errno 13] Permission denied: '/devel.log' 

所以我的問題是由於權限,因爲我沒有在我的celery_worker.conf文件中指定directory。一旦指定:

directory = /path/to/logs/ 

一切工作完美。

它可能不是相同的錯誤,但絕對檢查這些stderrstdout日誌將幫助