From 55b6b283b841363e98a3e2813c0ba24fd0aed048 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Wed, 30 Oct 2013 10:52:06 +0100 Subject: [PATCH] use uWSGIs locking --- isso.ini | 1 - isso/core.py | 7 ++----- isso/views/comment.py | 25 +++++++++++-------------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/isso.ini b/isso.ini index fcdf194..0e41f58 100644 --- a/isso.ini +++ b/isso.ini @@ -3,7 +3,6 @@ http = :8080 master = true processes = 4 spooler = %v/mail -queue = 1 module = isso virtualenv = . env = ISSO_SETTINGS=%v/sample.cfg diff --git a/isso/core.py b/isso/core.py index 3e5a8f4..3a606a0 100644 --- a/isso/core.py +++ b/isso/core.py @@ -197,13 +197,10 @@ class uWSGIMixin(Mixin): class Lock(): def __enter__(self): - while uwsgi.queue_get(0) == "LOCK": - time.sleep(0.01) - - uwsgi.queue_set(0, "LOCK") + uwsgi.lock() def __exit__(self, exc_type, exc_val, exc_tb): - uwsgi.queue_pop() + uwsgi.unlock() def spooler(args): try: diff --git a/isso/views/comment.py b/isso/views/comment.py index 58b98c0..f204b19 100644 --- a/isso/views/comment.py +++ b/isso/views/comment.py @@ -70,23 +70,20 @@ def new(app, environ, request, uri): data['mode'] = (app.conf.getboolean('moderation', 'enabled') and 2) or 1 data['remote_addr'] = utils.anonymize(str(request.remote_addr)) - # extract site's

title - if uri not in app.db.threads: - for host in app.conf.getiter('general', 'host'): - resp = http.curl('HEAD', host, uri) - if resp and resp.status == 200: - title = parse.title(resp.read()) - break - else: - return Response('URI does not exist', 404) - else: - title = app.db.threads[uri].title - with app.lock: if uri not in app.db.threads: - app.db.threads.new(uri, title) + for host in app.conf.getiter('general', 'host'): + resp = http.curl('HEAD', host, uri) + if resp and resp.status == 200: + title = parse.title(resp.read()) + break + else: + return Response('URI does not exist', 404) - logger.info('new thread: %s -> %s', uri, title) + app.db.threads.new(uri, title) + logger.info('new thread: %s -> %s', uri, title) + else: + title = app.db.threads[uri].title try: with app.lock: