Show More
@@ -32,6 +32,9 b" VERSION = (1, 2, 0, 'beta')" | |||||
32 | __dbversion__ = 3 #defines current db version for migrations |
|
32 | __dbversion__ = 3 #defines current db version for migrations | |
33 | __platform__ = platform.system() |
|
33 | __platform__ = platform.system() | |
34 |
|
34 | |||
|
35 | PLATFORM_WIN = ('Windows',) | |||
|
36 | PLATFORM_OTHERS = ('Linux', 'Darwin', 'FreeBSD',) | |||
|
37 | ||||
35 | try: |
|
38 | try: | |
36 | from rhodecode.lib.utils import get_current_revision |
|
39 | from rhodecode.lib.utils import get_current_revision | |
37 | _rev = get_current_revision() |
|
40 | _rev = get_current_revision() |
@@ -4,6 +4,19 b' from warnings import warn' | |||||
4 | from multiprocessing.util import Finalize |
|
4 | from multiprocessing.util import Finalize | |
5 | import errno |
|
5 | import errno | |
6 |
|
6 | |||
|
7 | from rhodecode import __platform__, PLATFORM_WIN | |||
|
8 | ||||
|
9 | if __platform__ in PLATFORM_WIN: | |||
|
10 | import ctypes | |||
|
11 | def kill(pid): | |||
|
12 | """kill function for Win32""" | |||
|
13 | kernel32 = ctypes.windll.kernel32 | |||
|
14 | handle = kernel32.OpenProcess(1, 0, pid) | |||
|
15 | return (0 != kernel32.TerminateProcess(handle, 0)) | |||
|
16 | ||||
|
17 | else: | |||
|
18 | kill = os.kill | |||
|
19 | ||||
7 | class LockHeld(Exception):pass |
|
20 | class LockHeld(Exception):pass | |
8 |
|
21 | |||
9 |
|
22 | |||
@@ -58,9 +71,9 b' class DaemonLock(object):' | |||||
58 | pidfile = open(self.pidfile, "r") |
|
71 | pidfile = open(self.pidfile, "r") | |
59 | pidfile.seek(0) |
|
72 | pidfile.seek(0) | |
60 | running_pid = int(pidfile.readline()) |
|
73 | running_pid = int(pidfile.readline()) | |
61 |
|
74 | |||
62 | pidfile.close() |
|
75 | pidfile.close() | |
63 |
|
76 | |||
64 | if self.debug: |
|
77 | if self.debug: | |
65 | print 'lock file present running_pid: %s, checking for execution'\ |
|
78 | print 'lock file present running_pid: %s, checking for execution'\ | |
66 | % running_pid |
|
79 | % running_pid | |
@@ -68,19 +81,19 b' class DaemonLock(object):' | |||||
68 | # process PID |
|
81 | # process PID | |
69 | if running_pid: |
|
82 | if running_pid: | |
70 | try: |
|
83 | try: | |
71 |
|
|
84 | kill(running_pid, 0) | |
72 | except OSError, exc: |
|
85 | except OSError, exc: | |
73 | if exc.errno in (errno.ESRCH, errno.EPERM): |
|
86 | if exc.errno in (errno.ESRCH, errno.EPERM): | |
74 | print "Lock File is there but the program is not running" |
|
87 | print "Lock File is there but the program is not running" | |
75 |
print "Removing lock file for the: %s" % running_pid |
|
88 | print "Removing lock file for the: %s" % running_pid | |
76 | self.release() |
|
89 | self.release() | |
77 | else: |
|
90 | else: | |
78 | raise |
|
91 | raise | |
79 | else: |
|
92 | else: | |
80 | print "You already have an instance of the program running" |
|
93 | print "You already have an instance of the program running" | |
81 |
print "It is running as process %s" % running_pid |
|
94 | print "It is running as process %s" % running_pid | |
82 | raise LockHeld() |
|
95 | raise LockHeld() | |
83 |
|
96 | |||
84 | except IOError, e: |
|
97 | except IOError, e: | |
85 | if e.errno != 2: |
|
98 | if e.errno != 2: | |
86 | raise |
|
99 | raise | |
@@ -90,7 +103,7 b' class DaemonLock(object):' | |||||
90 | """ |
|
103 | """ | |
91 | if self.debug: |
|
104 | if self.debug: | |
92 | print 'trying to release the pidlock' |
|
105 | print 'trying to release the pidlock' | |
93 |
|
106 | |||
94 | if self.callbackfn: |
|
107 | if self.callbackfn: | |
95 | #execute callback function on release |
|
108 | #execute callback function on release | |
96 | if self.debug: |
|
109 | if self.debug: |
General Comments 0
You need to be logged in to leave comments.
Login now