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 7848379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:10:47+00:00 2026-06-02T18:10:47+00:00

I notice this behavior in python for the pool allocation. Even though I have

  • 0

I notice this behavior in python for the pool allocation. Even though I have 20 processes in the pool, when I do a map_async for say 8 processes, instead of throwing all the processes to execute, I get only 4 executing. when those 4 finish, it sends two more, and then when those two finish is sends one.

When I throw more than 20 at it, it runs all 20, until it starts to get less than 20 in the queue, when the above behavior repeats.

I assume this is done on purpose, but it looks weird. My goal is to have the requests processed as soon as they come in and obviously this behavior does not fit.

Using python 2.6 with billiard for maxtasksperchild support

Any ideas how can I improve it?

Code:

mypool = pool.Pool(processes=settings['num-processes'], initializer=StartChild, maxtasksperchild=10)

while True:
    lines = DbData.GetAll()
    if len(lines) > 0:
        print 'Starting to process: ', len(lines), ' urls'
        Res = mypool.map_async(RunChild, lines)
        Returns = Res.get(None)
        print 'Pool returns: ', idx, Returns
    else:
        time.sleep(0.5)
  • 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-02T18:10:50+00:00Added an answer on June 2, 2026 at 6:10 pm

    One way I deal with multiprocessing in Python is the following:

    I have data on which I want to use a function function().
    First I create a multiprocessing subclass:

    import multiprocessing
    
    class ProcessThread(multiprocessing.Process):
        def __init__(self, id_t, inputqueue, idqueue, function, resultqueue):
            self.id_t = id_t
            self.inputlist = inputqueue
            self.idqueue = idqueue
            self.function = function
            self.resultqueue = resultqueue
    
            multiprocessing.Process.__init__(self)
    
        def run(self):
            s = "process number: " + str(self.id_t) + " starting"
            print s
            result = []
    
            while self.inputqueue.qsize() > 0
                try:
                    inp = self.inputqueue.get()
                except Exception:
                    pass
                result = self.function(inp)
                while 1:
                   try:
                       self.resultqueue.put([self.id,])
                   except Exception:
                       pass
                   else:
                       break
                self.idqueue.put(id)
                return
    

    and the main function:

    inputqueue = multiprocessing.Queue()
    resultqueue = multiprocessing.Queue()
    idqueue = multiprocessing.Queue()
    
    def function(data):
        print data # or what you want
    
    for datum in data:
        inputqueue.put(datum)
    
    for i in xrange(nbprocess):
        ProcessThread(i, inputqueue, idqueue, function, resultqueue).start()
    

    and finally get results:

    results = []
    while idqueue.qsize() < nbprocess:
        pass
    while resultqueue.qsize() > 0:
        results.append(resultqueue.get())
    

    In this way you can control perfectly what is appended with process and other stuff.
    Using a multiprocessing inputqueue is an efficient technique only if the computation for each datum is quite slow (< 1,2 seconds) because of the concurrent access of the different process to the queues (that why I use exception). If your function computes very quickly, consider splitting up your data only once at the begining and put chunks of the dataset for every process at the beginning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I notice this thread: Fastish Python/Jython IPC , and I have a similar problem,
I have this error NOTICE: UNDEFINED VARIABLE: LOGO IN C:\WAMP\WWW\SITE\TOOLS\SMARTY\SYSPLUGINS\SMARTY_INTERNAL_DATA.PHP ON LINE 291 CALL
I notice this weird behavior where I change the column type from ntext to
Get this simple python code, same matching with re.compile instance. I noticed that even
Has anyone noticed this behavior before? This really threw me off... I would have
I notice that this method is provided in UIViewController .m files, but is commented
I am doing some exercises in my object-oriented javascript book, I notice that this:
So in the code below you'll notice the comment // This item is obfuscated
Can anyone notice an error in this coding??? NSString *textFilePath = [[NSBundle mainBundle] pathForResource:@test
I keep getting an Notice: Undefined index: did error with this query, and I'm

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.