Perhaps someone more fluent in Python's Multiprocessing Pool code could help me out. I am trying to connect to several hosts on my network simultaneously (N at any one time) over a socket connection and execute some RPC's. As one host finishes, I want to add the next host into the Pool to run until all are complete.
I have a class, HClass, with some methods to do so, and a list of hostnames contained in hostlist. But I am failing to grok any of the docs.python.org examples for Pool to get this working.
A short snippet of code to illustrate what I've got so far:
hostlist = [h1, h2, h3, h4, ....]
poolsize = 2
class HClass:
def __init__(self, hostname="default"):
self.hostname = hostname
def go(self):
# do stuff
# do more stuff
....
if __name__ == "__main__":
objs = [HClass(hostname=current_host) for current_host in hostlist]
pool = multiprocessing.pool(poolsize)
results = pool.apply_async(objs.go())
So far I am blessed with this traceback:
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/lib/python2.7/multiprocessing/pool.py", line 319, in _handle_tasks
put(task)
PicklingError: Can't pickle <type 'generator'>: attribute lookup __builtin__.generator failed
Where the process just hangs until I Control-C out of it.