File tree 2 files changed +4
-14
lines changed
2 files changed +4
-14
lines changed Original file line number Diff line number Diff line change 31
31
'cherrypy' ,
32
32
'bottle' ,
33
33
'clize' ,
34
+ 'lockfile' ,
34
35
],
35
36
include_package_data = True ,
36
37
dependency_links = [
Original file line number Diff line number Diff line change 5
5
import os
6
6
import hashlib
7
7
import base64
8
+ import lockfile
8
9
9
10
from datetime import datetime , timedelta
10
11
@@ -124,18 +125,9 @@ def increment_counter(self):
124
125
"""
125
126
path = settings .PASTE_FILES_ROOT
126
127
counter_file = os .path .join (path , 'counter' )
127
- lock_file = os .path .join (path , 'counter.lock' )
128
-
129
- # TODO : change lock implementation to use the lockfile lib
130
- # https://pypi.python.org/pypi/lockfile
131
- # The current lock implementation sucks. It skips some increment, and
132
- # still allows race conditions.
133
- if not os .path .isfile (lock_file ):
134
- try :
135
- # Aquire lock file
136
- with open (lock_file , "w" ) as flock :
137
- flock .write ('lock' )
128
+ lock = lockfile .LockFile (counter_file )
138
129
130
+ with lock :
139
131
# Read the value from the counter
140
132
try :
141
133
with open (counter_file , "r" ) as fcounter :
@@ -147,9 +139,6 @@ def increment_counter(self):
147
139
with open (counter_file , "w" ) as fcounter :
148
140
fcounter .write (str (counter_value ))
149
141
150
- finally :
151
- # remove lock file
152
- os .remove (lock_file )
153
142
154
143
def save (self ):
155
144
"""
You can’t perform that action at this time.
0 commit comments