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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:04:47+00:00 2026-06-01T11:04:47+00:00

In py2.6+, the multiprocessing module offers a Pool class, so one can do: class

  • 0

In py2.6+, the multiprocessing module offers a Pool class, so one can do:

class Volatile(object):
    def do_stuff(self, ...):
        pool = multiprocessing.Pool()
        return pool.imap(...)

However, with the standard Python implementation at 2.7.2, this approach soon leads to “IOError: [Errno 24] Too many open files”. Apparently the pool object never gets garbage collected, so its processes never terminate, accumulating whatever descriptors are opened internally. I think this because the following works:

class Volatile(object):
    def do_stuff(self, ...):
        pool = multiprocessing.Pool()
        result = pool.map(...)
        pool.terminate()
        return result

I would like to keep the “lazy” iterator approach of imap; how does the garbage collector work in that case? How to fix the code?

  • 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-01T11:04:48+00:00Added an answer on June 1, 2026 at 11:04 am

    In the end, I ended up passing the pool reference around and terminating it manually once the pool.imap iterator was finished:

    class Volatile(object):
        def do_stuff(self, ...):
            pool = multiprocessing.Pool()
            return pool, pool.imap(...)
    
        def call_stuff(self):
            pool, results = self.do_stuff()
            for result in results:
                # lazy evaluation of the imap
            pool.terminate()
    

    In case anyone stumbles upon this solution in the future: the chunksize parameter is very important in Pool.imap (as opposed to plain Pool.map, where it didn’t matter). I manually set it so that each process receives 1 + len(input) / len(pool) jobs. Leaving it to the default chunksize=1 gave me the same performance as if I didn’t use parallel processing at all… bad.

    I guess there’s no real benefit to using ordered imap vs. ordered map, I just personally like iterators better.

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

Sidebar

Related Questions

Before py2.6 it's been answered here. Difference between class foo and class foo(object) in
How can I open __init__.pyc here? >>> import stompservice <module 'stompservice' from 'C:\Python25\lib\site-packages\stompservice-0.1.0-py2.5.egg\stompservice\__init__.pyc'> All
I installed gmpy-1.11rc1.win32-py2.6.exe, but can't figure out how to use it, I can see
I have installed python 2.6.6 and pygame 2.6 from here: http://pygame.org/ftp/pygame-1.9.1.win32-py2.6.msi However, when I
I'm on Mac OS X 10.6. Python is 2.6.1. I've installed bencode module as
I'm attempting to add a video extension to the Python Markdown-2.0.3-py2.7.egg Things aren't working,
Just installed Django (with easy_install) and created a project, but can't get mysql to
I've moved my django application from one server to another, and spotted strange bug
I'm using the pywin32-216.win32-py2.6.exe package to install pywin32 on Python 2.6.5 (r265:79096, Mar 19
so i am using django and the django_registration module. When i visit a page,

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.