I had an issue today (now fixed) that I thought I might share.
Jump to last line if you are impatient.
I was playing with some custom python to write DHT22 readings to a text file, and then to an email.
Preparing to attempt to inject these readings into motion MMAL with Pi camera.
Suddenly, after some code changes I started to get a "segmentation fault" when running the modified script.
I immediately ran my backup script as a control, and to my dismay - the same thing happened.
As this is a solar powered mobile camera, and frequently suffers abrupt power loss from the solar regulator protecting the battery, I assumed disk damage.
Another Pi module with touch screen, and gparted to the rescue - some errors, but no fix.
I then ran apt-get update, and apt-get upgrade, and watched as, among other things, phython and C modules were upgraded.
Still no fix.
Checked my code very very carefully - 3 times, letter by letter.
Nope - that's fine
Still getting segfaults - expressed multiple expletives - threw some stuff at the armored camera box - still no fix....
Finally, I went away, had some food, and an afternoon siesta.
Upon returning, I once again tried to run my backup, but this time I used the "up" arrow key to scroll back through commands to a point where it worked.
I noticed that I had run the command as root (using sudo)
I hit enter, and held my breath, as it then informed me I had to designate a GPIO port in the command line - but NO SEGFAULT!!!
The moral of the story - take some time, think, and retrace your steps - also:
To a more interesting note - if you run crontab -e, it edits the user cron, if you sudo crontab -e, it edits the root cron.
jobs running from root's cron, run as root (obviously)
commands used here don't need sudo preceeding them. (another obvious fact)
but, can lead to stupid mistakes like this.
I hope this is of use to newbie somewhere.....
-To save you some time reading - try running python as root (sudo python script.py)-