Commit Graph

859 Commits

Author SHA1 Message Date
Daniele Varrazzo
0da4befe78 Added function to advance the state after flush attempt. 2010-04-23 13:28:38 +01:00
Daniele Varrazzo
f3b3483df3 Added a function to advance the state after a read attempt.
Dropped calls to PQisBusy/PQconsumeInput in the connection code.
2010-04-23 13:24:36 +01:00
Daniele Varrazzo
e82d2be64b More lenient test timeout for a slow (or busy) machine. 2010-04-23 13:24:35 +01:00
Daniele Varrazzo
1edbd16577 Dropped curs_get_last_result function.
The result is read from a pqpath function and put on the async_cursor by
a function that also checks for is presence and dismiss it after its
usage.
2010-04-23 13:24:35 +01:00
Daniele Varrazzo
a66de9808f Added 'pq_get_last_result()' function.
The function reads the last result after an asynchronous query.
2010-04-23 13:24:35 +01:00
Daniele Varrazzo
5be0fc52ca Reusable parts of the green polling refactored out.
The functions _conn_poll_connecting() and _conn_poll_query() will be
usable by the async connections too.
2010-04-23 13:24:35 +01:00
Daniele Varrazzo
df959c20be Making sync and async connection setup somewhat more consistent. 2010-04-23 13:24:35 +01:00
Daniele Varrazzo
d915cb12a8 Functions to poll in ready state moved on the connection. 2010-04-23 13:24:35 +01:00
Daniele Varrazzo
9f5d835de6 Functions conn_poll_* renamed to conn_poll_connect_*.
These functions are used only during async connections, not for polling
afterwards.
2010-04-23 13:24:35 +01:00
Daniele Varrazzo
d2d1160260 Documentation about coroutines support reviewed. 2010-04-23 13:20:56 +01:00
Daniele Varrazzo
7af0bf0b54 Set the async_status to ASYNC_DONE after a query with wait callback.
Failing in doing that broke notifications reception.

The responsibility for changing the async_status has been moved to the
poll function: this is consistent with how the async branch is
implemented.

With this commit all the test suite passes in "green" mode.
2010-04-21 16:20:16 +01:00
Daniele Varrazzo
d71520db9a Read the server version only after connection established. 2010-04-21 15:31:07 +01:00
Daniele Varrazzo
8fed0aa57d 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.
2010-04-21 15:21:33 +01:00
Daniele Varrazzo
c1f0d4d46c Read notifications when polling an idle sync connection. 2010-04-21 15:21:33 +01:00
Daniele Varrazzo
4bb0c3bdf6 Use the wait callback in the connection setup queries. 2010-04-21 15:21:33 +01:00
Daniele Varrazzo
0ec73a18b4 'pq_execute_command_locked()' calls the wait callback if set.
The function is called without holding the GIL. Because it is necessary
to execute the Python callback if set, we need to re-acquire the GIL and
tnen release it again. In order to correctly bookkeep the thread state,
the pointer of the _save variable is passed to the function.
2010-04-21 15:21:33 +01:00
Daniele Varrazzo
7a06c0455b Try to restore the connection state after a wait callback error. 2010-04-21 15:21:32 +01:00
Daniele Varrazzo
a54932ee9c Added documentation for the green features. 2010-04-21 15:21:32 +01:00
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