Hi,
Le ven. 1 mars 2019 à 02:12, Neil Schemenauer nas-python@arctrix.com a écrit :
I believe the correct fix is to use PEP 3121 per-interpreter module state. I created a new issue:
https://github.com/psycopg/psycopg2/issues/854
I think the fix is not trival as the psycopgmodule.c source code has change a fair bit to use the PEP 3121 APIs.
The problem is this function:
/* Return nonzero if the current one is the main interpreter */ static int psyco_is_main_interp(void) { 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(); }
https://github.com/psycopg/psycopg2/blob/599432552aae4941c2b282e9251330f1357...
I'm not sure that this code is safe. In CPython, iterating on interp->next is protected by a lock:
HEAD_LOCK(); ... HEAD_UNLOCK();
We already expose the main interpreter since Python 3.7: PyInterpreterState_Main(). psycopg can be modified to use directly this function rather than playing black magic with CPython internals.
IMHO it's a good thing that the compilation failed: that such bug is found :-)
Victor