<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 10 (filtered)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin-top:6.0pt;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
h1
        {margin-right:0cm;
        margin-bottom:12.0pt;
        margin-left:18.0pt;
        text-indent:-18.0pt;
        page-break-before:always;
        font-size:24.0pt;
        font-family:"Times New Roman";}
h1.CxSpFirst
        {margin-right:0cm;
        margin-bottom:0cm;
        margin-left:18.0pt;
        margin-bottom:.0001pt;
        text-indent:-18.0pt;
        page-break-before:always;
        font-size:24.0pt;
        font-family:"Times New Roman";}
h1.CxSpMiddle
        {margin-right:0cm;
        margin-bottom:0cm;
        margin-left:18.0pt;
        margin-bottom:.0001pt;
        text-indent:-18.0pt;
        page-break-before:always;
        font-size:24.0pt;
        font-family:"Times New Roman";}
h1.CxSpLast
        {margin-right:0cm;
        margin-bottom:12.0pt;
        margin-left:18.0pt;
        text-indent:-18.0pt;
        page-break-before:always;
        font-size:24.0pt;
        font-family:"Times New Roman";}
h4
        {margin-right:0cm;
        margin-left:53.85pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
h5
        {margin-right:0cm;
        margin-left:71.75pt;
        font-size:10.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p.StyleHeading4Left127cm, li.StyleHeading4Left127cm, div.StyleHeading4Left127cm
        {margin-right:0cm;
        margin-left:53.85pt;
        font-size:12.0pt;
        font-family:"Times New Roman";
        font-weight:bold;}
span.EmailStyle18
        {font-family:Arial;
        color:windowtext;}
@page Section1
        {size:595.3pt 841.9pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
        {page:Section1;}
/* List Definitions */
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
-->
</style>
</head>
<body lang=EN-GB link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Thanks Grisha for being so quickly on the case.</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Session.py also includes the solution to my problem, using
the Apache global locks.</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>I now have the following code to protect a section of script
that is using the database connection (it uses SQLite but would apply mutatis
mutandis to another database). I have restored multi-threading and all works
smoothly. </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>If this is the best way to do this, it might be worth a
mention in the next release of the documentation. I suppose ideally application
code shouldn’t use _apache.</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>from mod_python import apache</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>import _apache</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>import re</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>import sqlite</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>import userdatabase</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>import sys</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>users = None</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>apache.log_error ("userHandler initialising", apache.APLOG_INFO)</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>def beginDB (req):</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> _apache._global_lock(req.server,
None, 0)</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> global
users</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> if
not users:</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> try:</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> try:</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> defaultUser
= req.get_options ()["defaultUser"]</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> except:</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> defaultUser
= "guest"</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> users
= userdatabase.UserDatabase\</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> (sqlite.connect
(req.get_options ()["dbFile"],</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> 077,
autocommit=1), defaultUser)</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> except:</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> (type,
value, tb) = sys.exc_info()</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> apache.log_error
("Cannot access user database: %s (%s)" % (type, value),</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> apache.APLOG_ERR)</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> </span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>def endDB (req):</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> _apache._global_unlock(req.server,
None, 0)</span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'> </span></font></p>
</div>
</body>
</html>