2011-10-19 166 views
1

我有一個非常簡單的Python腳本:不明原因的段錯誤在Python

import Skype4Py 
from random import randint 
from time import strftime, sleep 
from os import system 

interval = 5 

def pickStatus(): 
    try: 
     handler = open("lines.txt", "r") 
     lines = handler.read().split("\n") 
     handler.close() 
     rand = randint(0, len(lines)) 
     line = lines[rand] 
     print strftime("%Y-%m-%d %I:%M %p [" + str(rand) + "] ") + line 
     system('notify-send "New status" "' + line + '"') 
     skype.CurrentUserProfile.MoodText = line 
     sleep(interval * 60) 
     pickStatus() 
    except KeyboardInterrupt: 
     pass 

if __name__ == '__main__': 
    skype = Skype4Py.Skype() 
    skype.Attach() 
    pickStatus() 

當我運行它,我有時得到此:

~$ python RandomStatus.py 
Segmentation fault 
~$ 

其他時間,不過,劇本運行得很好。我所有的其他Python腳本也能正常工作。這個錯誤並沒有給我足夠的上下文,甚至不知道在哪裏尋找。有任何想法嗎?即使只是獲得一些實際的調試信息的方式,將不勝感激。

+4

你確定它是Python的segfaulting,而不是你正在調用的程序'notify-send'嗎?你有沒有試過把'print'語句放在崩潰的地方? –

+0

當然'系統'導致一個子過程。是不是不可能seg段父母? –

+0

它看起來像是在skype.Attach()後發生。無論從哪裏來,我都會把它吐出一次:http://pastebin.com/EHJez3Zm –

回答

10

我和Skype4Py有類似的問題,至少在我的情況下,事實證明Skype4Py不能在Mac上使用64位Python。雖然有時你的腳本有效,但可能不適用於你。

如果您使用的是Mac,看到斯內德Deily的評論在這個問題上對如何運行32位的Python:How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions

而只是寫在上面的幾個小時後,我面臨着類似的間歇賽格Linux上的錯誤。在這種情況下,賽格故障走了,當我連接使用X11,而不是DBUS

Skype4Py.Skype(Transport='x11') 
4

純Python的東西極不可能導致seg故障。這裏突出的是Skype4Py。不知道那是什麼或來自哪裏,但我敢打賭這是罪魁禍首。

+0

+1:這不太可能是其他任何東西。 –

0

使用Skype4py 64位Linux系統上,我得到了類似的結果(段錯誤)後。 有人在Skype的論壇建議

import logging 
logging.basicConfig(level=logging.DEBUG) 

添加到腳本中,看看是怎麼回事,但它並沒有太大的幫助。

奇怪的是,它有時可以工作。我嘗試過多次啓動腳本,有時啓動腳本,但稍後會啓動腳本。

無論如何,測試了Steven提到的「Transport ='x11'」事情,而且它似乎修復了它。