From: Ian B. <ia...@co...> - 2003-08-27 01:08:29
|
On Tuesday, August 26, 2003, at 03:53 PM, Brad Bollenbach wrote: > On Tue, Aug 26, 2003 at 07:26:19PM +0100, Oisin Mulvihill wrote: > [snip Ian's comments] >> Hi, >> >> I said this already but I've used twisted and sqlobject successfully. >> I use > > Eh, it may *look* like you have. :) SQLObject is synchronous, Twisted > is asynchronous, there's no compatibility here. > > e.g. > > Person.select("hair_colour = 'blonde'") > > In Twisted, every method call must return as fast as possible > (basically, instantly). In the above .select() is at the mercy of how > many blondes you have in your system. By extension, so is the rest of > your code; nothing else will get executed until that .select() comes > back. > > A deferred (in Twisted) doesn't solve this, because .select() doesn't > know how to be asynchronous anyway so the code will block no matter > what you try to do. You can still use a deferred. I don't remember the specifics, but you can ask for a deferred on a blocking call, and that call is moved to another thread. Once the call is finished in that other thread the deferred in the main thread gets invoked. That's how *all* database access in Twisted works, because as far as I know none of the underlying drivers have asynchronous interfaces (at least not exported to Python). Twisted's native ORM (adbapi?) makes the asynchronous stuff easier, generating deferreds on its own and such, but I'm pretty sure it works the same underneath, putting database calls in a separate thread. Ian |