multiprocessing.Manager() leaves child process alive after deleting Model object.

Open
#149 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

The report names no files, tests, or entry points. First reproduce repeated creation and deletion of a pymc-bart Model while observing multiprocessing children, then inspect the Manager-created all_trees lifecycle. Done means the Manager child exits when the Model is deleted, without requiring manual process termination, with a regression test for repeated iterations.

Written by the indexing model from the issue text.

Description

Hello,

I am not quite sure if this can be considered a bug, but I thought I would share. Feel free to close if this is too much of an edge issue.

I am running a simulation using the bart model that involved creating and deleting the pymc model (with a bart component) in each iteration. I noticed that as I went through iterations I would accumulate python processes that were no longer using CPU but appeared to hold memory(~50-100mb).

When many iterations were done I started having OOM issues due to these processes gradually taking up memory. These processes would die once the main process dies.

These processes were not the multi-chain/multi-thread processes used in the training/inference (those associated processes were spun-up/down correctly).

I believe the issue comes from the multiprocessing.Manager() used to create the 'all_trees' list.

To resolve the issue I used the following codeblock after each iteration was complete.

import multiprocessing as mp

childs = mp.active_children()
    for child in childs:
        child.kill()

This resolves the issue of lingering processes.

I am not sure if this should be considered bug or not, since it only becomes an issue when a high number of bart models are being created in a single python script. And I don't know if there is really a good general solution to resolving this issue, because if you kill the child process created by the Manager to early, I would expect there to be issues with further use of the model.

That being said, I could see other users running into this issue if doing a highly iterative process and generally I would say that it having a process that doesn't die when the model is deleted is unexpected behavior. So I just wanted to share my experience for future users reference.

Feel free to close or remove this submission if it is unhelpful.

Thanks!

Dominant language
Python
Stars
160
Forks
36
Avg merge
6d 2h
Merged PRs (30d)
1

Getting set up

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 pymc-devs/pymc-bart

All issues in pymc-devs/pymc-bart

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.