Pools not being properly closed in contexts

Open
#277 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Start at billiard.pool.Pool and inspect how the with statement handles a pool after map_async().get(). Reproduce the intensive usage described and compare it with explicit close() and join(). Done means determining whether context-managed pools leave file descriptors open and documenting or correcting the expected cleanup behavior.

Written by the indexing model from the issue text.

Description

I'm using pools under a context (a with statement) as in this example:

from billiard.pool import Pool

with Pool() as pool:
    pool_map = pool.map_async(...)
    output = pool_map.get()

do_other_things_with_output()

I'd expect this code to be properly closing everything, but when using it intensively, suddenly I get a filedescriptor out of range in select() error.

I've managed to somehow fix it by explicitly closing and joining the pools:

from billiard.pool import Pool

with Pool() as pool:
    pool_map = pool.map_async(...)
    output = pool_map.get()
    pool.close()
    pool.join()

do_other_things_with_output()

But such change reveals as a quite important performance drop.

Is there something I'm missing or doing wrong? Is this really the expected behabiour?

Dominant language
Python
Stars
436
Forks
273
Avg merge
4d 19h
Merged PRs (30d)
5

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from celery/billiard

All issues in celery/billiard

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.