diff --git a/lib/extras.py b/lib/extras.py index ac784b8e..c3babf47 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -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: diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index b0074b10..d87f9ca8 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -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 { diff --git a/psycopg/green.c b/psycopg/green.c index 5fe0bebb..fc9605db 100644 --- a/psycopg/green.c +++ b/psycopg/green.c @@ -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; diff --git a/psycopg/green.h b/psycopg/green.h index a21a9a17..16e83046 100644 --- a/psycopg/green.h +++ b/psycopg/green.h @@ -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