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.extensions import POLL_OK, POLL_READ, POLL_WRITE
from psycopg2 import OperationalError from psycopg2 import OperationalError
def wait_select(conn, curs=None): def wait_select(conn):
"""Wait until a connection or cursor has data available. """Wait until a connection or cursor has data available.
The function is an example of a wait callback to be registered with The function is an example of a wait callback to be registered with
`~psycopg2.extensions.set_wait_callback()`. This function uses `!select()` `~psycopg2.extensions.set_wait_callback()`. This function uses `!select()`
to wait for data available. to wait for data available.
""" """
poll = (curs or conn).poll
while 1: while 1:
state = poll() state = conn.poll()
if state == POLL_OK: if state == POLL_OK:
break break
elif state == POLL_READ: 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 the connection is green, wait to finish connection */
if (green) { if (green) {
wait_rv = psyco_wait((PyObject *)self, Py_None); wait_rv = psyco_wait(self);
if (wait_rv) { if (wait_rv) {
Py_DECREF(wait_rv); Py_DECREF(wait_rv);
} else { } else {

View File

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

View File

@ -36,7 +36,7 @@ extern "C" {
#define psyco_set_wait_callback_doc \ #define psyco_set_wait_callback_doc \
"set_wait_callback(f) -- Register a callback function to block waiting for data.\n" \ "set_wait_callback(f) -- Register a callback function to block waiting for data.\n" \
"\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" \ "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" \ "libpq is called. Use `!register_wait_function(None)` to revert to the\n" \
"original behaviour (using blocking libpq functions).\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 PyObject *psyco_get_wait_callback(PyObject *self, PyObject *obj);
HIDDEN int psyco_green(void); 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); HIDDEN PGresult *psyco_exec_green(connectionObject *conn, const char *command);
#ifdef __cplusplus #ifdef __cplusplus