[PyGreSQL] [patch] relinquish GIL while connecting to database

Peter Schuller peter.schuller at infidyne.com
Thu Sep 11 04:37:47 EDT 2008


Hello,

I discovered recently that connection attempts hang the Python
interpreter for the duration of them. This is undesirable for various
reasons.

Attached is a patch that inserts Py_BEGIN_ALLOW_THREADS /
Py_END_ALLOW_THREADS before/after the connection attempts.

As far as I can tell, there is nothing being done that would cause a
problem by doing this (in terms of relying on global state in a
non-readonly fashion or similar). It would be interesting to know if
anyone knows the history here; whether the lack of relinquishing is an
oversight or something that was done on purpose.

I'm also attaching a small test-case that doesn't do much but launch
some threads to repeatedly connect/disconnect, which I used to get
some more confidence in the change (it runs at full speed until given
a KeyboardInterrupt).

The patch and test case are also available here:

   http://distfiles.scode.org/mlref/patch-pgmodule.c
   http://distfiles.scode.org/mlref/pgdbconntest.py

Any thoughts?

NOTE: The patch is against version 3.8.1 as I was unable to find a
working method of accessing the CVS repository. The cvsweb interface
is down, and I didn't find information on the location of the
repository itself.

-- 
/ Peter Schuller

PGP userID: 0xE9758B7D or 'Peter Schuller <peter.schuller at infidyne.com>'
Key retrieval: Send an E-Mail to getpgpkey at scode.org
E-Mail: peter.schuller at infidyne.com Web: http://www.scode.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-pgmodule.c
Type: text/x-csrc
Size: 599 bytes
Desc: not available
Url : http://mailman.vex.net/pipermail/pygresql/attachments/20080911/b5189278/attachment.c 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgdbconntest.py
Type: text/x-python
Size: 1461 bytes
Desc: not available
Url : http://mailman.vex.net/pipermail/pygresql/attachments/20080911/b5189278/attachment.py 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://mailman.vex.net/pipermail/pygresql/attachments/20080911/b5189278/attachment.pgp 


More information about the PyGreSQL mailing list