All pastes #391396 Raw Edit

Something

public python v1 · immutable
·published 2007-03-12 03:07 UTC
rendered paste body
#!/usr/bin/python"""homeunison.py"""import os, sys, timelockfile = "/tmp/homeunison.lock"locked = 0for i in range(100):    if locked:        break           try:        if not os.path.exists(lockfile):            open(lockfile, "w").write("%d" % os.getpid())            print i, "Wrote pid to file"            continue    except:        pass                      try:        if os.path.exists(lockfile):            pid = open(lockfile).readline()            if int(pid) == os.getpid():                locked = 1                print i, "Initiated lock"                continue    except:        pass            try:        if os.path.exists("/proc/%s" % pid):            cmdline = open("/proc/%s/cmdline" % pid).readline()            if not "homeunison" in cmdline:                os.remove(lockfile)                print i, "Removed stale lockfile"                continue        else:            os.remove(lockfile)            print i, "Removed stale lockfile"            continue                except:        pass       time.sleep(0.15)if locked:    print os.getpid(), "Wootadoo"    time.sleep(30)        try:        os.remove(lockfile)    except:        pass