use uWSGIs locking

This commit is contained in:
Martin Zimmermann 2013-10-30 10:52:06 +01:00
parent 9a8e0b524e
commit 55b6b283b8
3 changed files with 13 additions and 20 deletions

View File

@ -3,7 +3,6 @@ http = :8080
master = true master = true
processes = 4 processes = 4
spooler = %v/mail spooler = %v/mail
queue = 1
module = isso module = isso
virtualenv = . virtualenv = .
env = ISSO_SETTINGS=%v/sample.cfg env = ISSO_SETTINGS=%v/sample.cfg

View File

@ -197,13 +197,10 @@ class uWSGIMixin(Mixin):
class Lock(): class Lock():
def __enter__(self): def __enter__(self):
while uwsgi.queue_get(0) == "LOCK": uwsgi.lock()
time.sleep(0.01)
uwsgi.queue_set(0, "LOCK")
def __exit__(self, exc_type, exc_val, exc_tb): def __exit__(self, exc_type, exc_val, exc_tb):
uwsgi.queue_pop() uwsgi.unlock()
def spooler(args): def spooler(args):
try: try:

View File

@ -70,7 +70,7 @@ def new(app, environ, request, uri):
data['mode'] = (app.conf.getboolean('moderation', 'enabled') and 2) or 1 data['mode'] = (app.conf.getboolean('moderation', 'enabled') and 2) or 1
data['remote_addr'] = utils.anonymize(str(request.remote_addr)) data['remote_addr'] = utils.anonymize(str(request.remote_addr))
# extract site's <h1> title with app.lock:
if uri not in app.db.threads: if uri not in app.db.threads:
for host in app.conf.getiter('general', 'host'): for host in app.conf.getiter('general', 'host'):
resp = http.curl('HEAD', host, uri) resp = http.curl('HEAD', host, uri)
@ -79,15 +79,12 @@ def new(app, environ, request, uri):
break break
else: else:
return Response('URI does not exist', 404) return Response('URI does not exist', 404)
app.db.threads.new(uri, title)
logger.info('new thread: %s -> %s', uri, title)
else: else:
title = app.db.threads[uri].title title = app.db.threads[uri].title
with app.lock:
if uri not in app.db.threads:
app.db.threads.new(uri, title)
logger.info('new thread: %s -> %s', uri, title)
try: try:
with app.lock: with app.lock:
rv = app.db.comments.add(uri, data) rv = app.db.comments.add(uri, data)