Re: Problem with multiprocessing

2009-09-02 Thread Roy Hyunjin Han

On 09/02/2009 04:51 AM, Peter Otten wrote:

tleeuwenb...@gmail.com wrote:


I have a problem using multiprocessing in a simple way. I created a
file, testmp.py, with the following contents:

---
import multiprocessing as mp

p = mp.Pool(5)

def f(x):
   return x * x

print map(f, [1,2,3,4,5])
print p.map(f, [1,2,3,4,5])


I'm too lazy to read the docs, so I just tinkered:

import multiprocessing as mp
import testmp

p = mp.Pool(5)

def f(x):
   return x * x

if __name__ == "__main__":
 print map(f, [1,2,3,4,5])
 print p.map(testmp.f, [1,2,3,4,5])


Yes, to use the multiprocessing module, you must make your script 
importable, so runtime statements should go into a __main__ 
conditional.  This way, when multiprocessing imports the module for each 
of its threads, the actual runtime code only gets executed once in the 
parent thread, which has the lock.  At least, that is what I think is 
happening.



import multiprocessing as mp

def f(x):
return x * x

if __name__ == '__main__':
p = mp.Pool(5)
print map(f, [1,2,3,4,5])
print p.map(f, [1,2,3,4,5])


http://docs.python.org/library/multiprocessing.html

--
http://invisibleroads.com
Connecting Python developers with local businesses

--
http://mail.python.org/mailman/listinfo/python-list


Python documentation servers

2009-08-10 Thread Roy Hyunjin Han
Are there issues with the python documentation servers?
http://docs.python.org/
The site has been really slow to respond all weekend.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: confused with subprocess.Popen

2009-05-12 Thread Roy Hyunjin Han
There's a great article by Doug Hellmann on subprocess.
http://www.doughellmann.com/PyMOTW/subprocess/

On Sun, May 10, 2009 at 1:37 AM, Soumen banerjee  wrote:
> Thanks!, i have found that alternately setting shell=True also works
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Man Bites Python

2009-04-16 Thread Roy Hyunjin Han
Hahaha!

On Thu, Apr 16, 2009 at 10:27 AM, Aahz  wrote:
> http://news.yahoo.com/s/nm/20090415/od_nm/us_python_odd_1/print
> --
> Aahz (a...@pythoncraft.com)           <*>         http://www.pythoncraft.com/
>
> Why is this newsgroup different from all other newsgroups?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list