Skip to content

Commit c5138f5

Browse files
author
Richard Jones
committed
sqlite backend uses the global lock again
roundup-server uses ForkingMixIn (yay, simultaneous accesses with mysql and postgresql)
1 parent 3d83fdb commit c5138f5

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Feature:
88
- added isset method to HTMLProperty
99
- database export now exports full journals too
1010
- tracker name at end of page title (sf rfe 926840)
11+
- roundup-server now uses the ForkingMixin
1112

1213
Fixed:
1314
- web CSV export was busted (as was any action returning a result)
@@ -22,6 +23,7 @@ Fixed:
2223
- roundup-admin install checks for existing tracker in target home
2324
- grouping (and sorting) by multilink in RDBMS backends (sf bug 655702)
2425
- roundup scripts may now be asked for their version (sf rfe 798657)
26+
- sqlite backend had stopped using the global lock
2527

2628

2729
2004-03-27 0.7.0b2

roundup/backends/back_anydbm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.140 2004-04-02 05:58:43 richard Exp $
18+
#$Id: back_anydbm.py,v 1.141 2004-04-07 01:12:25 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in a
2020
database chosen by anydbm. It is guaranteed to always be available in python
2121
versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
@@ -741,7 +741,6 @@ def close(self):
741741
'''
742742
if self.lockfile is not None:
743743
locking.release_lock(self.lockfile)
744-
if self.lockfile is not None:
745744
self.lockfile.close()
746745
self.lockfile = None
747746

roundup/backends/back_sqlite.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_sqlite.py,v 1.23 2004-03-31 23:08:08 richard Exp $
1+
# $Id: back_sqlite.py,v 1.24 2004-04-07 01:12:26 richard Exp $
22
'''Implements a backend for SQLite.
33
44
See https://pysqlite.sourceforge.net/ for pysqlite info
@@ -12,6 +12,7 @@
1212
import os, base64, marshal
1313

1414
from roundup import hyperdb, date, password
15+
from roundup.backends import locking
1516
from roundup.backends import rdbms_common
1617
import sqlite
1718

@@ -57,6 +58,12 @@ def open_connection(self):
5758
# ensure files are group readable and writable
5859
os.umask(0002)
5960

61+
# lock the database
62+
lockfilenm = os.path.join(self.dir, 'lock')
63+
self.lockfile = locking.acquire_lock(lockfilenm)
64+
self.lockfile.write(str(os.getpid()))
65+
self.lockfile.flush()
66+
6067
(self.conn, self.cursor) = self.sql_open_connection()
6168

6269
try:
@@ -210,10 +217,17 @@ def sql_close(self):
210217
connection.
211218
'''
212219
try:
213-
self.conn.close()
214-
except sqlite.ProgrammingError, value:
215-
if str(value) != 'close failed - Connection is closed.':
216-
raise
220+
try:
221+
self.conn.close()
222+
except sqlite.ProgrammingError, value:
223+
if str(value) != 'close failed - Connection is closed.':
224+
raise
225+
finally:
226+
# always release the lock
227+
if self.lockfile is not None:
228+
locking.release_lock(self.lockfile)
229+
self.lockfile.close()
230+
self.lockfile = None
217231

218232
def sql_rollback(self):
219233
''' Squash any error caused by us having closed the connection (and

roundup/scripts/roundup_server.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
"""Command-line script that runs a server over roundup.cgi.client.
1919
20-
$Id: roundup_server.py,v 1.43 2004-04-05 23:43:04 richard Exp $
20+
$Id: roundup_server.py,v 1.44 2004-04-07 01:12:26 richard Exp $
2121
"""
2222
__docformat__ = 'restructuredtext'
2323

@@ -26,7 +26,7 @@
2626
from roundup import __version__ as roundup_version
2727

2828
import sys, os, urllib, StringIO, traceback, cgi, binascii, getopt, imp
29-
import BaseHTTPServer, socket, errno
29+
import SocketServer, BaseHTTPServer, socket, errno
3030

3131
# Roundup modules of use here
3232
from roundup.cgi import cgitb, client
@@ -98,7 +98,8 @@ def run_cgi(self):
9898
self.send_error(403, self.path)
9999
except:
100100
exc, val, tb = sys.exc_info()
101-
if hasattr(socket, 'timeout') and exc == socket.timeout:
101+
if hasattr(socket, 'timeout') and isinstance(val, socket.timeout):
102+
# we can't send socket timeout errors back to the client, duh
102103
s = StringIO.StringIO()
103104
traceback.print_exc(None, s)
104105
self.log_message(str(s.getvalue()))
@@ -462,8 +463,12 @@ def run(port=PORT, success_message=None):
462463
# obtain server before changing user id - allows to use port <
463464
# 1024 if started as root
464465
address = (hostname, port)
466+
server_klass = BaseHTTPServer.HTTPServer
467+
class server_klass(SocketServer.ForkingMixIn,
468+
BaseHTTPServer.HTTPServer):
469+
pass
465470
try:
466-
httpd = BaseHTTPServer.HTTPServer(address, RoundupRequestHandler)
471+
httpd = server_klass(address, RoundupRequestHandler)
467472
except socket.error, e:
468473
if e[0] == errno.EADDRINUSE:
469474
raise socket.error, \

0 commit comments

Comments
 (0)