0

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()
3
Contributors
6
Replies
59
Views
3 Years
Discussion Span
Last Post by delta_frost
Featured Replies
  • 1

    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() Read More

  • 1

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

0

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.

1

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()
Votes + Comments
excellent
1

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.