I have this simple first multiprocessing code in pyton,but I encounter a BSOD when running it.Can anyone please point out what is wrong with it ?

import multiprocessing
def cracker():
    print "Hello"
    return

procs = []
for i in range(8):
    p = multiprocessing.Process(target = cracker)
    procs.append(p)
    p.start()

for p in procs:
    p.join()

Recommended Answers

All 6 Replies

Upgrade to linux !

Not a viable option :P
I actually meant to do some sort of benchmarking by finding out primes in parallel by dividing the task by ranges between the 8 cores on my i7.But running the above code simply freezes the system,not to mention various BSODs at times.

Your main code is not protected for importing, which multiprocessing module uses, this works:

import multiprocessing
def cracker():
    print "Hello"
    return

if __name__ == '__main__':
    procs = []
    for i in range(8):
        p = multiprocessing.Process(target = cracker)
        procs.append(p)
        p.start()

    for p in procs:
        p.join()
commented: excellent +13

Thanks pyTony.The code runs without freezing up the system but does not produce any output

http://s16.postimage.org/txd52wyyd/err.png

Do I have to import the module and use it in the IDLE to get that to work ?

You need to run it properly from command line double click etc. IDLE does not work.

Oh!! Thanks a lot.That saved a lot of time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.