[Psycopg] [psycopg] #192: Decimal support not safe for use with multiple sub interpreters.
psycopg
fog at initd.org
Fri Oct 19 03:12:16 CEST 2007
#192: Decimal support not safe for use with multiple sub interpreters.
-----------------------------+----------------------------------------------
Reporter: GrahamDumpleton | Owner: fog
Type: defect | Status: new
Priority: normal | Milestone: PSYCOPG 2.0.6
Component: psycopg2 | Version: 2.0.5
Severity: normal | Resolution:
Keywords: |
-----------------------------+----------------------------------------------
Comment (by piro):
I have been testing with a per-interpreter cache into psycopg, but the
incompatibility between the GIL and multi-interps makes me feel the
solution not a safe one.
I have a different solution for the adaptation failure reported in your
discussion: register a Decimal adapter from Python using the following
code:
{{{
from decimal import Decimal
import psycopg2.extensions as ext
# Register the Py -> PG type adapter
ext.register_adapter(Decimal, ext.AsIs)
}}}
This way there will be a different adapter for each sub-interpreter and
adaptation won't fail.
When adapting from PG to Py you may obtain the Decimal from the wrong
interpreter. I don't think this is a serious issue, apart that
{{{isinstance()}}} is no more reliable.
Psycopg initializes the decimal module only once. If this seems a problem,
compile psycopg ''without'' decimal support using:
{{{
python setup.py build_ext -U HAVE_DECIMAL
}}}
and register a PG type for conversion to Python too:
{{{
# Register the PG -> Py type adapter
ext.register_type(ext.new_type(
(1700,), "DECIMAL",
lambda val, cur: val and Decimal(val)))
}}}
you will obtain instances of the same Decimal class in all the
interpreters anyway, because the adapters register is another module
shared structure.
Because mod_wsgi itself is abandoning the idea of multi-interpreters, i
agree with Fog about the futility to have psycopg2 multi-interps-safe, or
to consider this approach reliable at all.
--
Ticket URL: <http://www.initd.org/tracker/psycopg/ticket/192#comment:2>
psycopg <http://initd.org/>
psycopg
More information about the Psycopg
mailing list