From: richard Date: Wed, 7 Apr 2004 01:12:26 +0000 (+0000) Subject: sqlite backend uses the global lock again X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=abcbbc49e1cef01530ca28ab7d6aa08595afd8ac;p=roundup.git sqlite backend uses the global lock again roundup-server uses ForkingMixIn (yay, simultaneous accesses with mysql and postgresql) git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2262 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index 2004074..0e8da95 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,6 +8,7 @@ Feature: - added isset method to HTMLProperty - database export now exports full journals too - tracker name at end of page title (sf rfe 926840) +- roundup-server now uses the ForkingMixin Fixed: - web CSV export was busted (as was any action returning a result) @@ -22,6 +23,7 @@ Fixed: - roundup-admin install checks for existing tracker in target home - grouping (and sorting) by multilink in RDBMS backends (sf bug 655702) - roundup scripts may now be asked for their version (sf rfe 798657) +- sqlite backend had stopped using the global lock 2004-03-27 0.7.0b2 diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index 0d3d15f..b79d145 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.140 2004-04-02 05:58:43 richard Exp $ +#$Id: back_anydbm.py,v 1.141 2004-04-07 01:12:25 richard Exp $ '''This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several @@ -741,7 +741,6 @@ class Database(FileStorage, hyperdb.Database, roundupdb.Database): ''' if self.lockfile is not None: locking.release_lock(self.lockfile) - if self.lockfile is not None: self.lockfile.close() self.lockfile = None diff --git a/roundup/backends/back_sqlite.py b/roundup/backends/back_sqlite.py index e251710..f624fa0 100644 --- a/roundup/backends/back_sqlite.py +++ b/roundup/backends/back_sqlite.py @@ -1,4 +1,4 @@ -# $Id: back_sqlite.py,v 1.23 2004-03-31 23:08:08 richard Exp $ +# $Id: back_sqlite.py,v 1.24 2004-04-07 01:12:26 richard Exp $ '''Implements a backend for SQLite. See https://pysqlite.sourceforge.net/ for pysqlite info @@ -12,6 +12,7 @@ __docformat__ = 'restructuredtext' import os, base64, marshal from roundup import hyperdb, date, password +from roundup.backends import locking from roundup.backends import rdbms_common import sqlite @@ -57,6 +58,12 @@ class Database(rdbms_common.Database): # ensure files are group readable and writable os.umask(0002) + # lock the database + lockfilenm = os.path.join(self.dir, 'lock') + self.lockfile = locking.acquire_lock(lockfilenm) + self.lockfile.write(str(os.getpid())) + self.lockfile.flush() + (self.conn, self.cursor) = self.sql_open_connection() try: @@ -210,10 +217,17 @@ class Database(rdbms_common.Database): connection. ''' try: - self.conn.close() - except sqlite.ProgrammingError, value: - if str(value) != 'close failed - Connection is closed.': - raise + try: + self.conn.close() + except sqlite.ProgrammingError, value: + if str(value) != 'close failed - Connection is closed.': + raise + finally: + # always release the lock + if self.lockfile is not None: + locking.release_lock(self.lockfile) + self.lockfile.close() + self.lockfile = None def sql_rollback(self): ''' Squash any error caused by us having closed the connection (and diff --git a/roundup/scripts/roundup_server.py b/roundup/scripts/roundup_server.py index c14cdf6..8983c6f 100644 --- a/roundup/scripts/roundup_server.py +++ b/roundup/scripts/roundup_server.py @@ -17,7 +17,7 @@ """Command-line script that runs a server over roundup.cgi.client. -$Id: roundup_server.py,v 1.43 2004-04-05 23:43:04 richard Exp $ +$Id: roundup_server.py,v 1.44 2004-04-07 01:12:26 richard Exp $ """ __docformat__ = 'restructuredtext' @@ -26,7 +26,7 @@ from roundup import version_check from roundup import __version__ as roundup_version import sys, os, urllib, StringIO, traceback, cgi, binascii, getopt, imp -import BaseHTTPServer, socket, errno +import SocketServer, BaseHTTPServer, socket, errno # Roundup modules of use here from roundup.cgi import cgitb, client @@ -98,7 +98,8 @@ class RoundupRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): self.send_error(403, self.path) except: exc, val, tb = sys.exc_info() - if hasattr(socket, 'timeout') and exc == socket.timeout: + if hasattr(socket, 'timeout') and isinstance(val, socket.timeout): + # we can't send socket timeout errors back to the client, duh s = StringIO.StringIO() traceback.print_exc(None, s) self.log_message(str(s.getvalue())) @@ -462,8 +463,12 @@ def run(port=PORT, success_message=None): # obtain server before changing user id - allows to use port < # 1024 if started as root address = (hostname, port) + server_klass = BaseHTTPServer.HTTPServer + class server_klass(SocketServer.ForkingMixIn, + BaseHTTPServer.HTTPServer): + pass try: - httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler) + httpd = server_klass(address, RoundupRequestHandler) except socket.error, e: if e[0] == errno.EADDRINUSE: raise socket.error, \