multithreading - iterating over methods - Python -
i've created following threading utility, inside class domain:
def __run_threads(self, targets): concurrent.futures.threadpoolexecutor(max_workers=5) executor: future_job = { executor.submit(target): target target in targets } future in concurrent.futures.as_completed(future_job): try: data = future.result() except exception exc: self.log.exception(exc) else: self.log.info("data: %s" % data) that's it, may want terminate or initiate node, belongs class domain. in order make generic possible, want pass targets list, array of target executed:
targets = [ node.terminate_instance node in self.nodes ] or
targets = [ node.start_instance node in new_nodes ] self.__run_threads(targets) however, when execute function get:
test_domain.py", line 19, in test_constructor dobj = domain.domain(name="test_domain", cluster_size=1) file "domain.py", line 31, in __init__ self.__run_threads(om_node.start_instance) file "domain.py", line 71, in __run_threads future_job = { executor.submit(target): target target in targets } typeerror: 'instancemethod' object not iterable how can iterate on list of methods in python?
the traceback shows you're doing this:
self.__run_threads(om_node.start_instance) so you're passing single method instance __run_threads, rather list of instance methods, method expects (and explicitly stated want pass it). need make caller pass list:
self.__run_threads([om_node.start_instance]) # or list comprehension provides multiple instance methods, in examples.
Comments
Post a Comment