I’ve got a fairly simple Python script:
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()
When I run it, I sometimes get this:
~$ python RandomStatus.py
Segmentation fault
~$
Other times, though, the script runs just fine. All my other Python scripts also work fine. This error doesn’t really give me enough context to even know where to look. Any ideas? Even just a way to get some actual debug info would be appreciated.
I had a similar problem with Skype4Py and, at least in my case, it turned out that Skype4Py doesn’t work with 64-bit Python on the Mac. Might not apply to you though since your script works sometimes.
If you’re using a Mac, see the Ned Deily’s comment in this question for how to run 32-bit Python: How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions
And just a few hours after writing the above, I faced a similar intermittent seg fault on Linux. In this case, the seg fault went away when I connected using X11 instead of DBUS