Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o, Alec Warner <antarus@g.o>
Cc: Zac Medico <zmedico@g.o>
Subject: Re: [gentoo-portage-dev] [PATCH 2/2] Add iter_completed convenience function (bug 648790)
Date: Mon, 26 Feb 2018 03:28:00
Message-Id: 2e602408-92ea-ac42-c332-32e74b4756ad@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH 2/2] Add iter_completed convenience function (bug 648790) by Alec Warner
1 On 02/25/2018 07:17 PM, Alec Warner wrote:
2 >
3 >
4 > On Sun, Feb 25, 2018 at 8:50 PM, Zac Medico <zmedico@g.o
5 > <mailto:zmedico@g.o>> wrote:
6 >
7 > The iter_completed function is similar to asyncio.as_completed, but
8 > takes an iterator of futures as input, and includes support for
9 > max_jobs and max_load parameters. The default values for max_jobs
10 > and max_load correspond to multiprocessing.cpu_count().
11 >
12 > Example usage for async_aux_get:
13 >
14 >   import portage
15 >   from portage.util.futures.iter_completed import iter_completed
16 >
17 >   portdb = portage.portdb
18 >   future_cpv = {}
19 >
20 >
21 > I'm not sure I grasp the purpose of this dict, can't we just modify the
22 > async aux get to return the cpv from the future?
23
24 If we do that then we should probably return all of the other aux_get
25 inputs too, including mylist, mytree, and myrepo. Pretty soon it feels
26 like there's a lot of clutter here. If we leave the burden to the
27 caller, then the API is simpler, and it's not much of a burden to the
28 caller anyway.
29
30 >   def future_generator():
31 >     for cpv in portdb.cp_list('sys-apps/portage'):
32 >       future = portdb.async_aux_get(cpv, portage.auxdbkeys)
33 >       future_cpv[id(future)] = cpv
34 >       yield future
35 >
36 >
37 > for cpv in portdb.cp_list('...'):
38 >    yield portdb.async_aux_get(cpv, portage.auxdbkeys)
39 >  
40 >
41 >   for future in iter_completed(future_generator()):
42 >     cpv = future_cpv.pop(id(future))
43 >     try:
44 >       result = future.result()
45 >     except KeyError as e:
46 >       # aux_get failed
47 >       print('error:', cpv, e)
48 >     else:
49 >       print(cpv, result)
50 >
51 >
52 > for future in iter_completed(future_generator()):
53 >   try:
54 >     cpv, result = future.result() 
55 >   except KeyError as e:
56 >     print('error', cpv, e)
57 >  
58 >
59 > Or do we expect callers to need other things to key off of in this API?
60
61 Yeah it's complicated because of the number of input arguments to
62 aux_get. You can have the same cpv existing in multiple repos. It's so
63 much simpler to let the caller manage the mapping from input arguments
64 to future instance.
65 --
66 Thanks,
67 Zac

Attachments

File name MIME type
signature.asc application/pgp-signature