From 8fed0aa57d588c3655423a3d25ece01662719836 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 21 Apr 2010 12:42:25 +0100 Subject: [PATCH] Forbid COPY-related methods in green mode. With the current implementation, at best they would silently block. They actually hang everything. Implementation posponed after some refactoring of the polling system, because it will be probably possible to provide an implementation for 'poll()' during COPY which is good for both async and green modes. --- doc/src/advanced.rst | 3 +++ psycopg/cursor.h | 6 ++++++ psycopg/cursor_type.c | 5 +++++ tests/__init__.py | 8 +++++++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/src/advanced.rst b/doc/src/advanced.rst index 13def38f..a595ce52 100644 --- a/doc/src/advanced.rst +++ b/doc/src/advanced.rst @@ -429,6 +429,9 @@ callback (using `!select()` to block) is provided as .. _SQLAlchemy: http://www.sqlalchemy.org/ .. __: http://www.postgresql.org/docs/8.4/static/libpq-async.html +.. warning:: + :ref:`COPY commands ` are currently not supported when a wait callback + is registered, but they will be probably implemented in a future release. .. testcode:: diff --git a/psycopg/cursor.h b/psycopg/cursor.h index 68a087ac..613ed9d3 100644 --- a/psycopg/cursor.h +++ b/psycopg/cursor.h @@ -116,6 +116,12 @@ if ((self)->conn->async_cursor != NULL) { \ "while an asynchronous query is underway"); \ return NULL; } +#define EXC_IF_GREEN(cmd) \ +if (psyco_green()) { \ + PyErr_SetString(PyExc_NotImplementedError, #cmd " cannot be used " \ + "with an asynchronous callback (yet)."); \ + return NULL; } + #ifdef __cplusplus } #endif diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index 2d4751e4..17d19721 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -34,6 +34,7 @@ #include "psycopg/psycopg.h" #include "psycopg/cursor.h" #include "psycopg/connection.h" +#include "psycopg/green.h" #include "psycopg/pqpath.h" #include "psycopg/typecast.h" #include "psycopg/microprotocols.h" @@ -1206,6 +1207,7 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs) EXC_IF_CURS_CLOSED(self); EXC_IF_CURS_ASYNC(self, copy_from); + EXC_IF_GREEN(copy_from); quoted_delimiter = psycopg_escape_string((PyObject*)self->conn, sep, 0, NULL, NULL); if (quoted_delimiter == NULL) { @@ -1311,6 +1313,8 @@ psyco_curs_copy_to(cursorObject *self, PyObject *args, PyObject *kwargs) EXC_IF_CURS_CLOSED(self); EXC_IF_CURS_ASYNC(self, copy_to); + EXC_IF_GREEN(copy_to); + quoted_delimiter = psycopg_escape_string((PyObject*)self->conn, sep, 0, NULL, NULL); if (quoted_delimiter == NULL) { PyErr_NoMemory(); @@ -1395,6 +1399,7 @@ psyco_curs_copy_expert(cursorObject *self, PyObject *args, PyObject *kwargs) EXC_IF_CURS_CLOSED(self); EXC_IF_CURS_ASYNC(self, copy_expert); + EXC_IF_GREEN(copy_expert); sql = _psyco_curs_validate_sql_basic(self, sql); diff --git a/tests/__init__.py b/tests/__init__.py index df4b7a13..eeeb5087 100755 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -51,7 +51,13 @@ def test_suite(): suite.addTest(types_basic.test_suite()) suite.addTest(types_extras.test_suite()) suite.addTest(test_lobject.test_suite()) - suite.addTest(test_copy.test_suite()) + + if not green: + suite.addTest(test_copy.test_suite()) + else: + import warnings + warnings.warn("copy not implemented in green mode: skipping tests") + suite.addTest(test_notify.test_suite()) suite.addTest(test_async.test_suite()) suite.addTest(test_green.test_suite())