diff --git a/kallithea/lib/pidlock.py b/kallithea/lib/pidlock.py --- a/kallithea/lib/pidlock.py +++ b/kallithea/lib/pidlock.py @@ -12,6 +12,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from __future__ import print_function + import errno import os from multiprocessing.util import Finalize @@ -50,7 +52,7 @@ class DaemonLock(object): def _on_finalize(lock, debug): if lock.held: if debug: - print 'lock held finalizing and running lock.release()' + print('lock held finalizing and running lock.release()') lock.release() def lock(self): @@ -60,7 +62,7 @@ class DaemonLock(object): """ lockname = str(os.getpid()) if self.debug: - print 'running lock' + print('running lock') self.trylock() self.makelock(lockname, self.pidfile) return True @@ -68,7 +70,7 @@ class DaemonLock(object): def trylock(self): running_pid = False if self.debug: - print 'checking for already running process' + print('checking for already running process') try: with open(self.pidfile, 'r') as f: try: @@ -77,8 +79,8 @@ class DaemonLock(object): running_pid = -1 if self.debug: - print ('lock file present running_pid: %s, ' - 'checking for execution' % (running_pid,)) + print('lock file present running_pid: %s, ' + 'checking for execution' % (running_pid,)) # Now we check the PID from lock file matches to the current # process PID if running_pid: @@ -88,13 +90,13 @@ class DaemonLock(object): if exc.errno in (errno.ESRCH, errno.EPERM): print ("Lock File is there but" " the program is not running") - print "Removing lock file for the: %s" % running_pid + print("Removing lock file for the: %s" % running_pid) self.release() else: raise else: - print "You already have an instance of the program running" - print "It is running as process %s" % running_pid + print("You already have an instance of the program running") + print("It is running as process %s" % running_pid) raise LockHeld() except IOError as e: @@ -105,21 +107,21 @@ class DaemonLock(object): """releases the pid by removing the pidfile """ if self.debug: - print 'trying to release the pidlock' + print('trying to release the pidlock') if self.callbackfn: #execute callback function on release if self.debug: - print 'executing callback function %s' % self.callbackfn + print('executing callback function %s' % self.callbackfn) self.callbackfn() try: if self.debug: - print 'removing pidfile %s' % self.pidfile + print('removing pidfile %s' % self.pidfile) os.remove(self.pidfile) self.held = False except OSError as e: if self.debug: - print 'removing pidfile failed %s' % e + print('removing pidfile failed %s' % e) pass def makelock(self, lockname, pidfile): @@ -130,7 +132,7 @@ class DaemonLock(object): :param pidfile: the file to write the pid in """ if self.debug: - print 'creating a file %s and pid: %s' % (pidfile, lockname) + print('creating a file %s and pid: %s' % (pidfile, lockname)) dir_, file_ = os.path.split(pidfile) if not os.path.isdir(dir_):