mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
Use lockfile library instead of custom implementation
This commit is contained in:
parent
66fe5d4088
commit
85c0395c37
1
setup.py
1
setup.py
@ -31,6 +31,7 @@ setup(
|
|||||||
'cherrypy',
|
'cherrypy',
|
||||||
'bottle',
|
'bottle',
|
||||||
'clize',
|
'clize',
|
||||||
|
'lockfile',
|
||||||
],
|
],
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
dependency_links=[
|
dependency_links=[
|
||||||
|
@ -5,6 +5,7 @@ from __future__ import unicode_literals, absolute_import
|
|||||||
import os
|
import os
|
||||||
import hashlib
|
import hashlib
|
||||||
import base64
|
import base64
|
||||||
|
import lockfile
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
@ -124,18 +125,9 @@ class Paste(object):
|
|||||||
"""
|
"""
|
||||||
path = settings.PASTE_FILES_ROOT
|
path = settings.PASTE_FILES_ROOT
|
||||||
counter_file = os.path.join(path, 'counter')
|
counter_file = os.path.join(path, 'counter')
|
||||||
lock_file = os.path.join(path, 'counter.lock')
|
lock = lockfile.LockFile(counter_file)
|
||||||
|
|
||||||
# TODO : change lock implementation to use the lockfile lib
|
|
||||||
# https://pypi.python.org/pypi/lockfile
|
|
||||||
# The current lock implementation sucks. It skips some increment, and
|
|
||||||
# still allows race conditions.
|
|
||||||
if not os.path.isfile(lock_file):
|
|
||||||
try:
|
|
||||||
# Aquire lock file
|
|
||||||
with open(lock_file, "w") as flock:
|
|
||||||
flock.write('lock')
|
|
||||||
|
|
||||||
|
with lock:
|
||||||
# Read the value from the counter
|
# Read the value from the counter
|
||||||
try:
|
try:
|
||||||
with open(counter_file, "r") as fcounter:
|
with open(counter_file, "r") as fcounter:
|
||||||
@ -147,9 +139,6 @@ class Paste(object):
|
|||||||
with open(counter_file, "w") as fcounter:
|
with open(counter_file, "w") as fcounter:
|
||||||
fcounter.write(str(counter_value))
|
fcounter.write(str(counter_value))
|
||||||
|
|
||||||
finally:
|
|
||||||
# remove lock file
|
|
||||||
os.remove(lock_file)
|
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user