I'll go line by line:
1: This appears to be a defect: there should be no whitespace before the #. Anyway it's a "shebang line" which tells what interpreter to use. Some people would prefer to see #!/usr/bin/env bash which gives more flexibility if users want to run under a non-default version of bash.
5: Create a variable containing a path.
6: [ -f $TMP_FILE ] && exit means "If the file exists, exit (with success code, i.e. 0)." You are right that it could be written as an "if" statement. Also note that [ -f $TMP_FILE ] is actually shorthand for test -f $TMP_FILE; knowing this you can look at man test to see what the various options are.
7: Now that we know the file does not exist, we create it. Or at least we try to--this could fail for various reasons, and the return code is not checked! It is good practice to put set -e at the top of any shell script, which means "stop if there is an unchecked failure code."
10: Next we run Python. Not the user's choice of Python interpreter, but specifically the one is /usr/bin/. Again this is not best practice--best would be to have a #!/usr/bin/env python shebang line at the top of the Python script itself, and invoke it directly, allowing the user's environment to select the desired Python interpreter.
11: Now we remove $TMP_FILE, which would allow us to run again next time. Therefore it's a sort of "lock file," though not a very robustly implemented one. For example, what happens if the user interrupts the script by pressing Ctrl-C while the Python script is running? The lock file will be left behind. You could use the trap builtin in Bash to remove the lock file before exiting in this case.
Maybe you should just integrate the lock file functionality directly in Python, and get rid of this wrapper script. You can do that by putting this at the top of your Python script, and getting rid of the wrapper completely:
import errno
import fcntl
import sys
lockfile = open('/tmp/i_am_running', 'a')
try:
fcntl.flock(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError as ex:
if ex.errno == errno.EWOULDBLOCK:
sys.exit("oops, already running")
else:
raise
# now the file is locked, do whatever you need and it will unlock on exit
Finally, note that the canonical location for lock files like this on Linux systems is under /var/run/, not /tmp/.