From 8ba0f00d210fcbbfa89eff8d4e97dc6c6391b39b Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 4 Apr 2010 00:14:48 +0100 Subject: [PATCH] Added 'get_wait_callback()' function. --- lib/extensions.py | 2 +- psycopg/green.c | 19 +++++++++++++++++++ psycopg/green.h | 8 +++++++- psycopg/psycopgmodule.c | 2 ++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/extensions.py b/lib/extensions.py index f7431d18..7290d5b4 100644 --- a/lib/extensions.py +++ b/lib/extensions.py @@ -61,7 +61,7 @@ from _psycopg import ISQLQuote from _psycopg import QueryCanceledError, TransactionRollbackError try: - from _psycopg import set_wait_callback + from _psycopg import set_wait_callback, get_wait_callback except ImportError: pass diff --git a/psycopg/green.c b/psycopg/green.c index a49f818a..2a66d941 100644 --- a/psycopg/green.c +++ b/psycopg/green.c @@ -56,6 +56,25 @@ psyco_set_wait_callback(PyObject *self, PyObject *obj) } +/* Return the currently registered wait callback function. + * + * The function is exported by the _psycopg module. + */ +PyObject * +psyco_get_wait_callback(PyObject *self, PyObject *obj) +{ + PyObject *ret; + + ret = wait_callback; + if (!ret) { + ret = Py_None; + } + + Py_INCREF(ret); + return ret; +} + + /* Return nonzero if a wait callback should be called. */ int psyco_green() diff --git a/psycopg/green.h b/psycopg/green.h index 3c09b327..a21a9a17 100644 --- a/psycopg/green.h +++ b/psycopg/green.h @@ -47,8 +47,14 @@ extern "C" { "\n" \ "See `~psycopg2.extras.wait_select()` for an example of a wait callback\n" \ "implementation.\n" - HIDDEN PyObject *psyco_set_wait_callback(PyObject *self, PyObject *obj); + +#define psyco_get_wait_callback_doc \ +"get_wait_callback() -- Return the currently registered wait callback.\n" \ +"\n" \ +"Return `None` if no callback is currently registered.\n" +HIDDEN PyObject *psyco_get_wait_callback(PyObject *self, PyObject *obj); + HIDDEN int psyco_green(void); HIDDEN PyObject *psyco_wait(PyObject *conn, PyObject *curs); HIDDEN PGresult *psyco_exec_green(connectionObject *conn, const char *command); diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index 60c9c041..8b47944d 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -697,6 +697,8 @@ static PyMethodDef psycopgMethods[] = { #ifdef PSYCOPG_EXTENSIONS {"set_wait_callback", (PyCFunction)psyco_set_wait_callback, METH_O, psyco_set_wait_callback_doc}, + {"get_wait_callback", (PyCFunction)psyco_get_wait_callback, + METH_NOARGS, psyco_get_wait_callback_doc}, #endif {NULL, NULL, 0, NULL} /* Sentinel */