Python threads all executing on a single core
Posted
by
Rob Lourens
on Stack Overflow
See other posts from Stack Overflow
or by Rob Lourens
Published on 2010-12-21T06:09:26Z
Indexed on
2010/12/21
6:54 UTC
Read the original article
Hit count: 297
I have a Python program that spawns many threads, runs 4 at a time, and each performs an expensive operation. Pseudocode:
for object in list:
t = Thread(target=process, args=(object))
# if fewer than 4 threads are currently running, t.start(). Otherwise, add t to queue
But when the program is run, Activity Monitor in OS X shows that 1 of the 4 logical cores is at 100% and the others are at nearly 0. Obviously I can't force the OS to do anything but I've never had to pay attention to performance in multi-threaded code like this before so I was wondering if I'm just missing or misunderstanding something.
Thanks.
© Stack Overflow or respective owner