Skip to content Skip to sidebar Skip to footer

Python Multiprocessing: Attributeerror: 'test' Object Has No Attribute 'get_type'

short short version: I am having trouble parallelizing code which uses instance methods. Longer version: This python code produces the error: Error Traceback (most recent call las

Solution 1:

You're using multiprocessing map method incorrectly. According to python docs:

A parallel equivalent of the map() built-in function (it supports only one iterable argument though).

Where standard map:

Apply function to every item of iterable and return a list of the results.

Example usage:

from multiprocessing import Pool

deff(x):
    return x*x

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

What you're looking for is apply_async method:

deftest(self):
    url = "http://nba.com"
    self.pool = Pool(processes=1)
    for x inrange(0, 3):
        self.pool.apply_async(self.f, args=(self, url))
        self.pool.apply_async(self.g, args=(self, url, 1))
    sleep(10)

Solution 2:

The error indicates you are trying to read an attribute which is not defined for the object Test.

AttributeError: 'Test' object has no attribute 'get_type'"

In your class test, you haven't defined get_type method or any other attribute hence the error.

Post a Comment for "Python Multiprocessing: Attributeerror: 'test' Object Has No Attribute 'get_type'"