yet another confusion with multiprocessing error, 'module' object has no attribute 'f'

Posted by gatoatigrado on Stack Overflow See other posts from Stack Overflow or by gatoatigrado
Published on 2010-05-06T17:08:01Z Indexed on 2010/05/06 17:18 UTC
Read the original article Hit count: 213

Filed under:
|

I know this has been answered before, but it seems that executing the script directly "python filename.py" does not work. I have Python 2.6.2 on SuSE Linux.

Code:

#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
p = Pool(1)
def f(x):
    return x*x
p.map(f, [1, 2, 3])

Command line:

> python example.py
Process PoolWorker-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 231, in _bootstrap
    self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
    self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.6/multiprocessing/pool.py", line 57, in worker
    task = get()
File "/usr/lib/python2.6/multiprocessing/queues.py", line 339, in get
    return recv()
AttributeError: 'module' object has no attribute 'f'

© Stack Overflow or respective owner

Related posts about python

Related posts about multiprocessing