Which core am I running on?

Gerhard Häring gh at ghaering.de
Tue Feb 10 10:47:17 CET 2009


psaffrey at googlemail.com wrote:
> On 9 Feb, 12:24, Gerhard Häring <g... at ghaering.de> wrote:
>> http://objectmix.com/python/631346-parallel-python.html
>>
> 
> Hmm. In fact, this doesn't seem to work for pp. When I run the code
> below, it says everything is running on the one core.
> 
> import pp
> import random
> import time
> from string import lowercase
> 
> ncpus = 3
> 
> def timedCharDump(waittime, char):
> 	time.sleep(waittime)
> 	mycore = open("/proc/%i/stat" % os.getpid()).read().split()[39]
> 	print "I'm doing stuff!", mycore, char
> 	return char
> 
> job_server = pp.Server(ncpus, ppservers=())
> 
> jobdetails = [ (random.random(), letter) for letter in lowercase ]
> 
> jobs = [ job_server.submit(timedCharDump,(jinput1, jinput2), (),
> ("os", "time",)) for jinput1, jinput2 in jobdetails ]
> 
> for job in jobs:
> 	print job()

Quick look again found this:

http://brokestream.com/procstat.html

I guess I counted wrong and it's actually column 38, not 39.

-- Gerhard




More information about the Python-list mailing list