Ahsan Imam wrote:

>Setting the variable did not help.
>I downloaded and built Python 2.1.2 yesterday.
>
>Products:
>zope-tinytable-0.8.2-2
>zope-zmysqlda-2.0.7-5
>
>>>>"Chris McDonough" <[EMAIL PROTECTED]> 01/24/02 12:22 PM >>>
>>>>
>Sigh.  Can you try to start Zope with the environment variable
>ZOPE_SECURITY_POLICY=PYTHON set to see if the problem continues?
>
>Are you using any database adapters or other C extensions?
>
>Are you sure that Zope is using the Python 2.1.2 that you installed?
>

Try applying this patch to db.py in ZMySQLDA.

It makes it so MySQLDA database connections reopen themselves when the 
DA object migrates between threads.
--- ../ZMySQLDA-orig/db.py      Thu Sep  6 23:45:35 2001
+++ db.py       Tue Jan  8 14:24:52 2002
@@ -104,6 +104,7 @@
 import string, sys
 from string import strip, split, find, upper, rfind
 from time import time
+import thread
 
 hosed_connection = (
     CR.SERVER_GONE_ERROR,
@@ -180,11 +181,12 @@
         self.connection=connection
         self.kwargs = kwargs = self._parse_connection_string(connection)
         self.db=apply(self.Database_Connection, (), kwargs)
-       self.transactions = self.db.server_capabilities & CLIENT.TRANSACTIONS
+       self.transactions = self.db.server_capabilities & CLIENT.TRANSACTIONS
         if self._try_transactions == '-':
             self.transactions = 0
         elif not self.transactions and self._try_transactions == '+':
             raise NotSupportedError, "transactions not supported by this server"
+        self._v_tid = thread.get_ident()
 
     def _parse_connection_string(self, connection):
         kwargs = {'conv': self.conv}
@@ -275,6 +277,10 @@
         desc=None
         result=()
         db=self.db
+        # Because we might not be thread-safe across threads...
+        if not self._v_tid == thread.get_ident():
+            db=self.db=apply(self.Database_Connection, (), self.kwargs)
+            self._v_tid = thread.get_ident()
         try:
             for qs in filter(None, map(strip,split(query_string, '\0'))):
                 qtype = upper(split(qs, None, 1)[0])
@@ -297,7 +303,7 @@
         except OperationalError, m:
             if m[0] not in hosed_connection: raise
             # Hm. maybe the db is hosed.  Let's restart it.
-           db=self.db=apply(self.Database_Connection, (), self.kwargs)
+            db=self.db=apply(self.Database_Connection, (), self.kwargs)
             return self.query(query_string, max_rows)
 
         if desc is None: return (),()

Reply via email to