Changed 'psyco_wait()' to only take the connection.

This commit is contained in:
Daniele Varrazzo 2010-04-04 03:07:43 +01:00
parent 0dd5d3f1d9
commit 127f92f9db
4 changed files with 9 additions and 10 deletions

View File

@ -488,16 +488,15 @@ import select
from psycopg2.extensions import POLL_OK, POLL_READ, POLL_WRITE
from psycopg2 import OperationalError
def wait_select(conn, curs=None):
def wait_select(conn):
"""Wait until a connection or cursor has data available.
The function is an example of a wait callback to be registered with
`~psycopg2.extensions.set_wait_callback()`. This function uses `!select()`
to wait for data available.
"""
poll = (curs or conn).poll
while 1:
state = poll()
state = conn.poll()
if state == POLL_OK:
break
elif state == POLL_READ:

View File

@ -366,7 +366,7 @@ conn_sync_connect(connectionObject *self)
/* if the connection is green, wait to finish connection */
if (green) {
wait_rv = psyco_wait((PyObject *)self, Py_None);
wait_rv = psyco_wait(self);
if (wait_rv) {
Py_DECREF(wait_rv);
} else {

View File

@ -115,7 +115,7 @@ have_wait_callback()
* The function returns the return value of the called function.
*/
PyObject *
psyco_wait(PyObject *conn, PyObject *curs)
psyco_wait(connectionObject *conn)
{
PyObject *rv;
PyObject *cb;
@ -125,7 +125,7 @@ psyco_wait(PyObject *conn, PyObject *curs)
return NULL;
}
rv = PyObject_CallFunctionObjArgs(cb, conn, curs, NULL);
rv = PyObject_CallFunctionObjArgs(cb, conn, NULL);
Py_DECREF(cb);
return rv;
@ -160,7 +160,7 @@ psyco_exec_green(connectionObject *conn, const char *command)
/* Ensure the query reached the server. */
conn->async_status = ASYNC_WRITE;
pyrv = PyObject_CallFunctionObjArgs(cb, conn, NULL, NULL);
pyrv = PyObject_CallFunctionObjArgs(cb, conn, NULL);
if (!pyrv) {
Dprintf("psyco_exec_green: error in callback sending query");
goto clear;
@ -170,7 +170,7 @@ psyco_exec_green(connectionObject *conn, const char *command)
/* Loop reading data using the user-provided wait function */
conn->async_status = ASYNC_READ;
pyrv = PyObject_CallFunctionObjArgs(cb, conn, NULL, NULL);
pyrv = PyObject_CallFunctionObjArgs(cb, conn, NULL);
if (!pyrv) {
Dprintf("psyco_exec_green: error in callback reading result");
goto clear;

View File

@ -36,7 +36,7 @@ extern "C" {
#define psyco_set_wait_callback_doc \
"set_wait_callback(f) -- Register a callback function to block waiting for data.\n" \
"\n" \
"The callback must should signature :samp:`fun({conn}, {cur}=None)` and\n" \
"The callback should have signature :samp:`fun({conn})` and\n" \
"is called to wait for data available whenever a blocking function from the\n" \
"libpq is called. Use `!register_wait_function(None)` to revert to the\n" \
"original behaviour (using blocking libpq functions).\n" \
@ -56,7 +56,7 @@ HIDDEN PyObject *psyco_set_wait_callback(PyObject *self, PyObject *obj);
HIDDEN PyObject *psyco_get_wait_callback(PyObject *self, PyObject *obj);
HIDDEN int psyco_green(void);
HIDDEN PyObject *psyco_wait(PyObject *conn, PyObject *curs);
HIDDEN PyObject *psyco_wait(connectionObject *conn);
HIDDEN PGresult *psyco_exec_green(connectionObject *conn, const char *command);
#ifdef __cplusplus