Animeta
Animeta

Reputation: 1343

multiprocessing.Pool.map() method is throwing AttributeError

from multiprocessing import Pool

class A:
  def __init__(self, n):
    self.n = n

  def __foo(self, i):
    return i + 1

  def bar(self):
    l = list(map(self.__foo, range(self.n)))
    print(len(l))

  def baz(self):
    pool = Pool(2)
    l = list(pool.map(self.__foo, range(self.n)))
    print(len(l))

a = A(3)
a.bar()
a.baz()

Here is the brief output:

3
AttributeError: 'A' object has no attribute '__foo'

I want use Pool to process a big dataframe, but Pool.map doesn't work — how to deal with it?

Upvotes: 0

Views: 202

Answers (1)

AKX
AKX

Reputation: 168863

Don't use a double-underscore name for __foo; the name gets mangled.

Use _foo if you want to mark a member internal or "private".

Upvotes: 1

Related Questions