Commit Graph

891 Commits

Author SHA1 Message Date
Daniele Varrazzo
127f92f9db Changed 'psyco_wait()' to only take the connection. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
0dd5d3f1d9 Correctly flush async queries in 'green' mode. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
8ba0f00d21 Added 'get_wait_callback()' function. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
a7c41a0388 'pq_execute()' uses the user wait callback if provided. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
55270cab9f 'poll()' can raise a Python exception in case of error. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
442b3b2f6c Added 'psyco_exec_green()' to replace 'PQexec' using the user-provided block function. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
6dd6bee217 Added async read support to 'connection.poll()'. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
1108172e4c The test suite can be run against the green path. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
1607f89bb1 Avoid the locks dance when reading the connection socket number.
It is a fast and non critical operation, so the lock is not required.
Furthermore, called from the wait callback creates a deadlock.
2010-04-21 15:21:32 +01:00
Daniele Varrazzo
389ad08965 Use the wait callback during connection if set. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
04d66a6c82 Added poll implementation for sync connection with external wait. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
1446f046e9 Added wait callback and functions to deal with it. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
02a28ff028 Notifications are automatically read after each query.
Added tests for basic notifications process.
2010-04-21 15:09:14 +01:00
Daniele Varrazzo
12ef826d50 Dropped redundant call to conn_notice_process().
If the connection is sync, notices will be processed by pq_fetch()
downstream.

If the connection is async, here we have only sent the query: no result
is ready yet, and neither notices have had a chance to arrive: they will
be retrieved later by pq_is_busy().

Added tests to check the above statement don't break.
2010-04-21 15:09:14 +01:00
Daniele Varrazzo
bcfcea4b49 Fixed reference leak in notify reception. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
2af29b467d Added missing points to the changelog. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
d8f4ed1a04 Fixed documentation and example for asynchronous notifications. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
6fecc36b7f Connection method 'executing()' renamed to 'isexecuting()'. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
7ee09353ec Connection method 'issync()' changed into the attribute 'async'. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
7cf52da969 Ensure to close the connections in the doctests to avoid deadlocks. 2010-04-21 15:09:13 +01:00
Daniele Varrazzo
ac6938a26a Fixed async documentation after cursor.poll() dropped. 2010-04-21 15:09:13 +01:00
Jan Urbański
a57a9976b4 Fix the NOTIFY example to use the correct APIs 2010-04-21 15:09:13 +01:00
Jan Urbański
067161d5f3 Remove fileno() and poll() from cursors
Instead, the code should be using the fileno() and poll() methods of
the cursor's connection. Handle the case when poll() is called on an
already built connection as a request to poll the asynchronous query
(if there is one) and get NOTIFY events.
Update the tests to reflect that change, add a test for NOTIFY.
2010-04-21 15:09:13 +01:00
Daniele Varrazzo
b7327a349d FAQs grouped in themes. 2010-04-21 15:09:13 +01:00
Jan Urbański
f06f557111 Add one more test for errors involving two cursors 2010-04-20 23:01:10 +01:00
Jan Urbański
c4ebc0f702 Handle errors in asynchronous queries.
Do it by keeping the reference to the last PGresult in the cursor and
calling pq_fetch() before ending the asynchronous execution. This
takes care of handling the possible error state of the PGresult and
also allows the removal of the needsfetch flag, since now after
execution ends the results are already fetched and parsed.
2010-04-20 23:01:01 +01:00
Federico Di Gregorio
249b3ef88f Merged tests from piro and jan async fixes branches 2010-04-14 10:01:37 +02:00
Jan Urbański
5f4ef5da13 Make connection.executing() be True during an async connection attempt. 2010-04-14 10:00:37 +02:00
Jan Urbański
463724690c Set the execution status to ASYNC_READ after flushing all output.
Without this a query that did not get flushed completely to the server
would cause cursor.poll() to always go into the curs_poll_send()
branch even if it was retuning ASYNC_READ.

Bug report by Daniele Varrazzo.
2010-04-14 09:56:44 +02:00
Jan Urbański
4574bde3a2 Check for possible errors from PQflush.
Noticed by Daniele Varrazzo.
2010-04-14 09:56:44 +02:00
Jan Urbański
61f890c317 Set the initial connection status to CONN_STATUS_SETUP.
Without it the changes in e79528f9aa1f7457573720fce5548302fefffd37 are
never used.
2010-04-14 09:56:44 +02:00
Jan Urbański
6108e4dc92 Make the first poll() of an asynchronous connection return POLL_WRITE.
This hides from the user the libpq's implementation detail of
requiring the first select() to wait for the connection socket to
become writable and makes it possible to have a uniform select loop
for both cursors and connections, in which you always start by polling
the object and then acting according to the result from poll().

Idea and implementation by Daniele Varrazzo.
2010-04-14 09:56:44 +02:00
Jan Urbański
4afc1baf35 Make polling a cursor that's not in an async query raise an exception.
If there is an asynchronous query, polling a cursor that did not
initiate it will raise an exception. Polling while there is no
asynchronous query underway still works, because the user needs to
have a way to get asynchronous NOTIFYs.
2010-04-14 09:56:44 +02:00
Federico Di Gregorio
a90935930b Merge remote branch 'piro/fix22' into python2 2010-04-14 08:57:30 +02:00
Federico Di Gregorio
eaa97def73 Applied GC patch from Michael Tharp 2010-04-14 08:50:16 +02:00
Daniele Varrazzo
431920b367 Added recipe to get Python floats from Postgres decimals in the FAQ. 2010-04-14 01:05:36 +01:00
Daniele Varrazzo
0ac4c8ac17 Typecasters section in the extensions doc reordered. 2010-04-14 00:41:03 +01:00
Daniele Varrazzo
d162c08cfa PY* and MX* typecasters imported into the extensions module. 2010-04-14 00:27:28 +01:00
Daniele Varrazzo
54e9c89ea4 DECIMAL typecaster imported into the extensions module. 2010-04-14 00:20:16 +01:00
Daniele Varrazzo
595dc7effa Added a test to check poll() correctly calls PQflush.
When a large query is sent to the backend (and probably in high
concurrency situations), writing the query could block. In
this case PQflush() should be called until it returns 0. The test checks
this is done correctly.
2010-04-11 01:05:31 +01:00
Daniele Varrazzo
88fe5f91d2 Fixed parameters parsing in the connection constructor.
Keyword arguments were silently discarded.
2010-04-11 00:30:54 +01:00
Daniele Varrazzo
47ff5a6b01 test_async made properly executable. 2010-04-11 00:06:54 +01:00
Federico Di Gregorio
b8953cb345 Fixed Python 2.4 compatibility breakage 2010-04-09 12:53:38 +02:00
Federico Di Gregorio
0a33ed01f5 Added test for refcounting/gc bug reported by Michael Tharp 2010-04-08 18:42:20 +02:00
Daniele Varrazzo
6aaa50703e Added documentation for the new asynchronous support. 2010-04-08 13:25:17 +01:00
Daniele Varrazzo
d197346ce3 Added test to check that connections subclasses can be asynchronous. 2010-04-08 12:51:33 +01:00
Daniele Varrazzo
236b97045e Dropped README.async files referring to pre-2.2. 2010-04-08 10:51:30 +01:00
Daniele Varrazzo
e8286084e9 Free the GIL in blocking operations in V2 COPY FROM. 2010-04-07 23:52:53 +01:00
Daniele Varrazzo
aeec583ff1 Ensure running COPY in blocking mode. 2010-04-07 23:41:32 +01:00
Daniele Varrazzo
b114e25c31 Added some COPY tests. 2010-04-07 23:41:32 +01:00