You're using PsycoPG with multiple interpreters.
I had the same problem:
http://groups.google.com/group/django-users/browse_thread/thread/91aa6c088f6c090/929f2fd69307cd22
There is a reference to the psycopg2 ticket with patch attached to it,
unfortunately the psycopg site appears to be down due to maintenance... So I
am attaching a patch that I am using (not sure that this is the patch
included with the official 2.0.7).
On Sat, Aug 16, 2008 at 8:37 PM, jme <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm seeing this same problem, but i'm using psycopg1, does anyone know
> what the actual source of the problem is? I can't find what it might
> be in the psycopg2 changelogs to figure out how it's affecting
> psycopg1.
>
> Thanks,
>
> Jamie
>
> On Aug 5, 9:02 pm, "Norman Harman" <[EMAIL PROTECTED]> wrote:
> > Whit wrote:
> > > Hi,
> >
> > > It's a psycopg's problem. Solved in psycopg 2.0.7.
> >
> > Super awesome thanks!
> >
> > > Nice day, Vitek
> >
> > I will, now.
> >
> > --
> > Norman J. Harman Jr.
> > Senior Web Specialist, Austin American-Statesman
> >
> ___________________________________________________________________________
> > It's August! Keep your cool with the Statesman. Check out our hot
> > deals in print and online for back-to-school savings and more!
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Index: psycopg/psycopg.h
===================================================================
--- psycopg/psycopg.h (revision 885)
+++ psycopg/psycopg.h (revision 902)
@@ -131,5 +131,5 @@
/* the Decimal type, used by the DECIMAL typecaster */
-extern PyObject *decimalType;
+extern PyObject *psyco_GetDecimalType(void);
/* some utility functions */
Index: psycopg/psycopgmodule.c
===================================================================
--- psycopg/psycopgmodule.c (revision 901)
+++ psycopg/psycopgmodule.c (revision 902)
@@ -63,5 +63,4 @@
PyObject *psycoEncodings = NULL;
-PyObject *decimalType = NULL;
/** connect module-level function **/
@@ -331,5 +330,6 @@
#ifdef HAVE_DECIMAL
- microprotocols_add((PyTypeObject*)decimalType, NULL, (PyObject*)&asisType);
+ microprotocols_add((PyTypeObject*)psyco_GetDecimalType(),
+ NULL, (PyObject*)&asisType);
#endif
}
@@ -555,12 +555,53 @@
}
-/* psyco_decimal_init
-
- Initialize the module's pointer to the decimal type. */
-
-void
-psyco_decimal_init(void)
-{
+
+/* Return nonzero if the current one is the main interpreter */
+static int
+psyco_is_main_interp()
+{
+ static PyInterpreterState *main_interp = NULL; /* Cached reference */
+ PyInterpreterState *interp;
+
+ if (main_interp) {
+ return (main_interp == PyThreadState_Get()->interp);
+ }
+
+ /* No cached value: cache the proper value and try again. */
+ interp = PyInterpreterState_Head();
+ while (interp->next)
+ interp = interp->next;
+
+ main_interp = interp;
+ assert (main_interp);
+ return psyco_is_main_interp();
+}
+
+
+/* psyco_GetDecimalType
+
+ Return a new reference to the adapter for decimal type.
+
+ If decimals should be used but the module import fails, fall back on
+ the float type.
+
+ If decimals are not to be used, return NULL.
+ */
+
+PyObject *
+psyco_GetDecimalType(void)
+{
+ PyObject *decimalType = NULL;
+ static PyObject *cachedType = NULL;
+
#ifdef HAVE_DECIMAL
+
+ /* Use the cached object if running from the main interpreter. */
+ int can_cache = psyco_is_main_interp();
+ if (can_cache && cachedType) {
+ Py_INCREF(cachedType);
+ return cachedType;
+ }
+
+ /* Get a new reference to the Decimal type. */
PyObject *decimal = PyImport_ImportModule("decimal");
if (decimal) {
@@ -573,5 +614,13 @@
Py_INCREF(decimalType);
}
-#endif
+
+ /* Store the object from future uses. */
+ if (can_cache && !cachedType) {
+ cachedType = decimalType;
+ }
+
+#endif /* HAVE_DECIMAL */
+
+ return decimalType;
}
@@ -732,5 +781,4 @@
psycoEncodings = PyDict_New();
psyco_encodings_fill(psycoEncodings);
- psyco_decimal_init();
/* set some module's parameters */
Index: psycopg/typecast_basic.c
===================================================================
--- psycopg/typecast_basic.c (revision 900)
+++ psycopg/typecast_basic.c (revision 902)
@@ -121,4 +121,5 @@
{
PyObject *res = NULL;
+ PyObject *decimalType;
char *buffer;
@@ -128,5 +129,7 @@
return PyErr_NoMemory();
strncpy(buffer, s, (size_t) len); buffer[len] = '\0';
+ decimalType = psyco_GetDecimalType();
res = PyObject_CallFunction(decimalType, "s", buffer);
+ Py_DECREF(decimalType);
PyMem_Free(buffer);