I have my python script set to run from cron in Ubuntu Server. However it might take longer time to finish, before another cron event will try to start it. I would like to determine such case from script itself and if running then gracefully terminate it from python script.
There are two obvious solutions:

Some kind of lock file, which it checks. If the lock file exists, then don't start, otherwise create it. (Or more aptly, in true python 'ask for forgiveness, not permission' style, try to make it and catch the error if it exists - stopping a race condition). You need to be careful to ensure this gets cleaned up when the script ends, however - even on errors, otherwise it could block future runs. Traditionally this is a .pid file which contains the process id of the running process.
Use ps to check for the running process. With this solution it is harder to stop the race condition, however.
How to determine if my python script is running?