changeset 1194:07963dd1f0f1 beta

fixes for issue #133
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 02 Apr 2011 00:42:17 +0200
parents 523382549c45
children 74251f8004d2
files rhodecode/__init__.py rhodecode/lib/pidlock.py
diffstat 2 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/__init__.py	Fri Apr 01 18:46:24 2011 +0200
+++ b/rhodecode/__init__.py	Sat Apr 02 00:42:17 2011 +0200
@@ -32,6 +32,9 @@
 __dbversion__ = 3 #defines current db version for migrations
 __platform__ = platform.system()
 
+PLATFORM_WIN = ('Windows',)
+PLATFORM_OTHERS = ('Linux', 'Darwin', 'FreeBSD',)
+
 try:
     from rhodecode.lib.utils import get_current_revision
     _rev = get_current_revision()
--- a/rhodecode/lib/pidlock.py	Fri Apr 01 18:46:24 2011 +0200
+++ b/rhodecode/lib/pidlock.py	Sat Apr 02 00:42:17 2011 +0200
@@ -4,6 +4,19 @@
 from multiprocessing.util import Finalize
 import errno
 
+from rhodecode import __platform__, PLATFORM_WIN
+
+if __platform__ in PLATFORM_WIN:
+    import ctypes
+    def kill(pid):
+        """kill function for Win32"""
+        kernel32 = ctypes.windll.kernel32
+        handle = kernel32.OpenProcess(1, 0, pid)
+        return (0 != kernel32.TerminateProcess(handle, 0))
+
+else:
+    kill = os.kill
+
 class LockHeld(Exception):pass
 
 
@@ -58,9 +71,9 @@
             pidfile = open(self.pidfile, "r")
             pidfile.seek(0)
             running_pid = int(pidfile.readline())
-            
+
             pidfile.close()
-            
+
             if self.debug:
                 print 'lock file present running_pid: %s, checking for execution'\
                 % running_pid
@@ -68,19 +81,19 @@
             # process PID
             if running_pid:
                 try:
-                    os.kill(running_pid, 0)
+                    kill(running_pid, 0)
                 except OSError, exc:
                     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 "It is running as process %s" % running_pid
                     raise LockHeld()
-                         
+
         except IOError, e:
             if e.errno != 2:
                 raise
@@ -90,7 +103,7 @@
         """
         if self.debug:
             print 'trying to release the pidlock'
-            
+
         if self.callbackfn:
             #execute callback function on release
             if self.debug: