- Hard limit on the connection.notices list to avoid them

growing indefinitely.
  Notices are treated as a queue: when the queue is full 
  drop the oldest notice.
This commit is contained in:
Daniele Varrazzo 2007-11-09 02:28:47 +00:00
parent e1dd9ca843
commit 277f57ffb0
2 changed files with 9 additions and 1 deletions

View File

@ -36,6 +36,9 @@ extern "C" {
#define CONN_STATUS_SYNC 3 #define CONN_STATUS_SYNC 3
#define CONN_STATUS_ASYNC 4 #define CONN_STATUS_ASYNC 4
/* Hard limit on the notices stored by the Python connection */
#define CONN_NOTICES_LIMIT 50
extern PyTypeObject connectionType; extern PyTypeObject connectionType;
typedef struct { typedef struct {

View File

@ -45,8 +45,13 @@ conn_notice_callback(void *args, const char *message)
if (self->protocol < 3 && strncmp(message, "ERROR", 5) == 0) if (self->protocol < 3 && strncmp(message, "ERROR", 5) == 0)
pq_set_critical(self, message); pq_set_critical(self, message);
else else {
PyList_Append(self->notice_list, PyString_FromString(message)); PyList_Append(self->notice_list, PyString_FromString(message));
/* Remove the oldest item if the queue is getting too long. */
if (PyList_GET_SIZE(self->notice_list) > CONN_NOTICES_LIMIT)
PySequence_DelItem(self->notice_list, 0);
}
} }
/* conn_connect - execute a connection to the dataabase */ /* conn_connect - execute a connection to the dataabase */