1

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.

Dan Hlavenka
  • 3,697
  • 8
  • 42
  • 60
  • 4
    Are you sure it's Python that's segfaulting and not the program `notify-send` that you're invoking? Have you tried putting in `print` statements to see where it's crashing? – Adam Rosenfield Oct 19 '11 at 19:41
  • Surely `system` leads to a subprocess. Isn't that unlikely to segfault the parent? – David Heffernan Oct 19 '11 at 19:45
  • It looks like it's happening right after skype.Attach(). Out of nowhere, I got it to spit this out once: http://pastebin.com/EHJez3Zm – Dan Hlavenka Oct 19 '11 at 19:52

3 Answers3

10

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

Skype4Py.Skype(Transport='x11')
Community
  • 1
  • 1
nioq
  • 3,215
  • 1
  • 23
  • 18
4

The plain Python stuff is exceptionally unlikely to lead to seg fault. What sticks out here is Skype4Py. No idea what that is or where it comes from, but I bet it's the culprit.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
0

After using Skype4py on 64bit Linux system I got similar results (segfault). Someone on Skype forums suggested to add

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

to the script, to see what is going on, but it didn't help much.

And the weird part is that it sometimes works. I tried starting the script many times, sometimes it starts but segfaults at some later point.

Anyway, tested the "Transport='x11'" thing that Steven mentioned, and it seems like it fixes it.

Janhouse
  • 376
  • 1
  • 11