On 16/05/11 13:38 +0200, Albert Cervera i Areny wrote:
> A Dilluns, 16 de maig de 2011 13:26:06, Cédric Krier va escriure:
> > The idea will be to have something like:
> > 
> >     queries = {}
> >     for record in self.browse(ids):
> >         queries[record.id] = Async(self.search, [...], order=[('x',
> > 'ASC')], limit=1)
> > 
> >     for id, query in queries.iteritems():
> >         ids = query.result()
> >         if ids:
> >             ...
> > 
> > The Async method will be in charge of setting a new cursor for the thread,
> > creating a thread and keep the result until the main thread will read it.
> > Of course, for backend that doesn't support multi-threading, the method
> > will do the query directly.
> 
> Having easy to use Async calls would be great. I think that in this case the 
> API could be optimized so the second loop "consumes" results as soon as 
> they're available so if the first one takes a long time to compute doesn't 
> lock 
> the rest. 

I think we will let to the dev to decide the order to process results.
It can be done with something like:

    while queries:
        for id, query in queries.iteritems():
            if query.finish():
                del queries[id]
                ids = query.result()
                ...

> What I don't know is how transactions work. If you create a new cursor will 
> it 
> create a new transaction too?

Not if the cursor comes from the same connection (in psycopg2 means).
So we will still work in the same transaction.

-- 
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: [email protected]
Website: http://www.b2ck.com/

Attachment: pgpSuJEoDim3D.pgp
Description: PGP signature

Reply via email to