diff --git a/deluge/ui/gtkui/ipcinterface.py b/deluge/ui/gtkui/ipcinterface.py index 2ee48fd21..046073399 100644 --- a/deluge/ui/gtkui/ipcinterface.py +++ b/deluge/ui/gtkui/ipcinterface.py @@ -35,7 +35,7 @@ import sys -import os.path +import os import base64 import deluge.rencode @@ -104,6 +104,20 @@ class IPCInterface(component.Component): reactor.run() sys.exit(0) else: + lockfile = socket + ".lock" + log.debug("Checking if lockfile exists: %s", lockfile) + if os.path.lexists(lockfile): + try: + os.kill(int(os.readlink(lockfile)), 0) + except OSError: + log.debug("Removing lockfile since it's stale.") + try: + os.remove(lockfile) + os.remove(socket) + except Exception, e: + log.error("Problem deleting lockfile or socket file!") + log.exception(e) + try: self.factory = Factory() self.factory.protocol = IPCProtocolServer