Skip to content

Resolve capture_output deadlock in multiprocessing environments#3957

Open
jsiirola wants to merge 22 commits into
Pyomo:mainfrom
jsiirola:capture-output-deadlock
Open

Resolve capture_output deadlock in multiprocessing environments#3957
jsiirola wants to merge 22 commits into
Pyomo:mainfrom
jsiirola:capture-output-deadlock

Conversation

@jsiirola
Copy link
Copy Markdown
Member

Fixes # .

Summary/Motivation:

#3908 pointed out that we could inadvertently trigger a deadlock in multiprocessing environments. This PR attempts to resolve that by switching from a threading.Lock to a multiprocessing.Lock if multiprocessing is being used in the python process.

I am not closing the issue as the original reporters have not confirmed if it actually resolves their use case.

As part of this, I needed to overhaul the import time test / reporting logic so that we can more accurately test import timing for multiprocessing environments.

Changes proposed in this PR:

  • Switch to a multiprocessing.Lock when multiprocessing is imported
  • Make sure that multiprocessing is not imported by pyomo.environ
  • Overhaul (and generalize) the import time reporting logic

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 80.64516% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.28%. Comparing base (6ffd3cb) to head (5e7ad72).

Files with missing lines Patch % Lines
pyomo/common/unittest.py 25.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3957      +/-   ##
==========================================
- Coverage   90.10%   88.28%   -1.82%     
==========================================
  Files         908      908              
  Lines      108344   108360      +16     
==========================================
- Hits        97620    95668    -1952     
- Misses      10724    12692    +1968     
Flag Coverage Δ
builders 29.12% <58.06%> (+<0.01%) ⬆️
default 86.08% <80.64%> (?)
expensive 35.14% <58.06%> (?)
linux 34.55% <58.06%> (-55.06%) ⬇️
linux_other 34.55% <58.06%> (-53.07%) ⬇️
oldsolvers 28.07% <58.06%> (+<0.01%) ⬆️
osx ?
win ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants