multiprocessing hick ups on windows

Hey everyone. I was playing around with some multiprocessing and I notice something strang… or at least something I wasn’t expecting. Can anyone tell me why the following code pastebin.com/R21RvtAn works one way and not the other? The code that doesn’t work seems to be rerunning the starting code instead of the class code like a thread would do.

Also… I wouldn’t run the test code. Just to say how much you really shouldn’t run that code without moding it a bit… it was design to just get my point across… I just want to know why the process is restarting all the way over instead of just calling the class instead and or if there is a fix around it instead of blocking the code from the outside.

For the sake of your computer… please, please, do no run the code… my final warning, lol.

This is explained in the Python docs (under “Safe importing of main module”).

Thanks… I didn’t scroll down far enough to see that. I guess they were sort of wrong when they said multiprocessing will be just as easy to use as threading was xD

Most of the core python community use unix/linux where this isn’t an issue so for them multiprocessing is just like threading. For myself (using XP), I made a wrapper module that first pipes whatever function/method I want to be “multi-processed” to a separate module and then runs it from there negating the need for the "if name == “main” hack. I can then use multi-core processing on the fly with statements like:

with multicore() as mc:
    results = mc.apply(my_func, *my_args)

“results” being a tuple with one result for each core. How you combine these results is then up to you. In python 3 they have the “concurrent” library which works a lot like this.