Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9066125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:40:09+00:00 2026-06-16T16:40:09+00:00

Perhaps someone more fluent in Python’s Multiprocessing Pool code could help me out. I

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:40:10+00:00Added an answer on June 16, 2026 at 4:40 pm

    I would try to keep interprocess communication down to a minimum. It looks like all you really need to send is the hostname string:

    for host in hostlist:
        pool.apply_async(worker, args = (host,), callback = on_return)
    

    For example,

    import multiprocessing as mp
    import time
    import logging
    
    logger = mp.log_to_stderr(logging.INFO)
    
    hostlist = ['h1', 'h2', 'h3', 'h4']*3
    poolsize = 2
    
    class HClass:
        def __init__(self, hostname="default"):
            self.hostname = hostname
    
        def go(self):
            logger.info('processing {h}'.format(h = self.hostname))
            time.sleep(1)
            return self.hostname
    
    def worker(host):
        h = HClass(hostname = host)
        return h.go()
    
    result = []
    def on_return(retval):
        result.append(retval)
    
    if __name__ == "__main__":
        pool = mp.Pool(poolsize)
        for host in hostlist:
            pool.apply_async(worker, args = (host,), callback = on_return)
        pool.close()
        pool.join()
        logger.info(result)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perhaps someone can help me out with this one: I'm using a basic search
An odd error here, perhaps someone can help track down source as it's attempting
this newbie here is smacking his head with webservices over Rails. Perhaps someone could
Can someone work out why my JScrollPane is not working. Perhaps something I may
Perhaps I'm having a Post-Ballmer-Peak Moment . I'm hoping that someone can help point
I'm hoping that someone can help me out with this problem, or at least
I have a pretty simple question which perhaps someone familiar with Server/Client design &
I know that NSDate does not represent a timezone, but perhaps someone can advise
Heads starting to hurt. I think I dropped into this too fast... Perhaps someone
I think I may have a misunderstanding of <xsl:variable\> and <xsl:value-of\> so perhaps someone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.