Threaded for loop

Carl Banks pavlovevidence at gmail.com
Sat Jan 13 19:05:40 EST 2007


Dennis Lee Bieber wrote:
> On 13 Jan 2007 12:15:44 -0800, "John" <weekender_ny at yahoo.com> declaimed
> the following in comp.lang.python:
>
> >
> > I want to do something like this:
> >
> > for i = 1 in range(0,N):
> >  for j = 1 in range(0,N):
> >    D[i][j] = calculate(i,j)
> >
> > I would like to now do this using a fixed number of threads, say 10
> > threads.
> > What is the easiest way to do the "parfor" in python?
> >
> > Thanks in advance for your help,
> > --j
>
> 	Don't know if it's the easiest -- and if "calculate" is a CPU-bound
> number cruncher with no I/O or other OS-blocking calls, it won't be
> faster either as the GIL will only let one run at a time, even on
> multi-core processors.

It could still be helpful if you'd like to get as much done as possible
in as short a time as possible, and you suspect that one or two cases
are likely to hold everything up.


Carl Banks




More information about the Python-list mailing list