[Twisted-web] pgasync (was: /freeform_post!!random causes exceptions)

Andrea Arcangeli andrea at cpushare.com
Tue Jan 18 17:00:08 MST 2005

On Tue, Jan 18, 2005 at 01:40:52PM -0600, J Turner wrote:
> DB API is the API used by all the synchronous modules, which probably
> represent 99.9% of the python database code out there.  There are two
> schools of thought on this one:

I was suggesting to do both at the same time ;).

> runInteraction takes a function as an argument.  Traditionally,
> this function was always run in a thread, so you could be free to, for
> example, make a blocking call using urllib.urlopen or something.  While
> pgasync could call the function that runInteraction passes to it, that
> function could *not* block.
> pgasync doesn't make a thread pool, and it won't (ever) run anything on a
> thread.  That was the principal goal when I started the project: Twisted
> is async, so I want it all async.

Good point, and perfectly clear, but it's not my problem, I'm not doing
blocking calls at all in the runInteraction. So if you make a wrapper
I'll be able to swap it.  Just place a big fat warning that no blocking
call should ever happen in the callback executed by runInteraction.

The only reason I'm using runInteraction at all, is to have access to
the cursor and to extract the description too, so I can do a careless
select * that then generates an hash, and I don't need to change a thing
in the query code if I modify the DB, all I get is a new field in the
hash (actually in the class, because the hash is passed in input to a
class that does setattr on itself depending on the hash contents).

I didn't get what you mean about problems with transactions.

I thought all runOperation are transacted automatically, so if I'm

	UPDATE ... ;
	UPDATE ... ;

it's like if they both run inside a:

	UPDATE ... ;
	UPDATE ... ;

atomic block. If I'm wrong, it means I've already a problem. I'm
depending on read committed guarnatees of pgsql for my code, and it must
definitely run inside a transaction (not like if I'm executing each
command in the psql shell without a BEGIN/COMMIT block around it).

If I'm wrong, it must be still possible to fix it without having to use
runInteraction every time, isn't it? adbapi executes a .commit every
time internally, that made me think I was safe.

Thanks for the help!

More information about the Twisted-web mailing list