More CPUs doen't equal more speed

Chris Angelico rosuav at gmail.com
Thu May 23 20:52:45 EDT 2019


On Fri, May 24, 2019 at 10:48 AM MRAB <python at mrabarnett.plus.com> wrote:
>
> On 2019-05-24 01:22, Chris Angelico wrote:
> > What I'd recommend is a thread pool. Broadly speaking, it would look
> > something like this:
> >
> > jobs = [...]
> >
> > def run_jobs():
> >      while jobs:
> >          try: job = jobs.pop()
> >          except IndexError: break # deal with race
> >
> Personally, I'd use a queue (from the 'queue' module), instead of a
> list, for the job pool.

It's not going to be materially different, since there's nothing
adding more jobs part way. Either way works, and for the sake of a
simple demo, I stuck to a core data type that any Python programmer
will know, rather than potentially introducing another module :) But
yes, the queue is a common choice here.

ChrisA



More information about the Python-list mailing list