Skip to content

Start autoimport cache workers without forking a threaded process - #964

Open
marlon-costa-dc wants to merge 3 commits into
python-rope:masterfrom
marlon-costa-dc:pr/autoimport-forkserver
Open

marlon-costa-dc wants to merge 3 commits into
python-rope:masterfrom
marlon-costa-dc:pr/autoimport-forkserver

Conversation

@marlon-costa-dc

@marlon-costa-dc marlon-costa-dc commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

AutoImport.generate_cache and generate_modules_cache run their workers in a ProcessPoolExecutor with the platform's default start method, which is fork on POSIX before Python 3.14. Forking a process that runs other threads, as editors, language servers and test runners usually do, can deadlock the child, and Python 3.12+ emits a DeprecationWarning on every such fork.

This starts the pool's workers with forkserver (the POSIX default since Python 3.14), or spawn where forkserver is unavailable, through one _process_pool() helper used by both call sites.

The new test selects the fork start method, starts a helper thread and generates both caches, asserting that no "use of fork()" warning is raised and the cache still answers searches.

Local run (CPython 3.13): ropetest/contrib/autoimport 44 passed; the one error, test_get_package_tuple_compiled, comes from that interpreter's statically linked _sqlite3 and is unrelated. pre-commit passes.

🤖 Generated with Claude Code

marlon-costa-dc and others added 2 commits November 21, 2026 23:37
`AutoImport.generate_cache` and `generate_modules_cache` used the platform's
default process start method, which is `fork` on POSIX before Python 3.14.
Forking a process that runs other threads, as editors, language servers and
test runners do, can deadlock the child, and Python 3.12+ warns on every such
fork. Start the pool's workers with `forkserver`, or `spawn` where it is
unavailable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.45%. Comparing base (ff8a306) to head (4f7ea41).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #964   +/-   ##
=======================================
  Coverage   95.44%   95.45%           
=======================================
  Files         134      134           
  Lines       26910    26942   +32     
=======================================
+ Hits        25685    25717   +32     
  Misses       1225     1225           

☔ View full report in Codecov by Harness.
📢 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.

On macOS the recorded warnings also held `ResourceWarning: unclosed database`
for sqlite connections other tests leave to the garbage collector. The test
is about forking a threaded process, so assert that no "use of fork()"
warning appears.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@marlon-costa-dc

Copy link
Copy Markdown
Contributor Author

The upstream test workflows wait for maintainer approval on fork PRs. For reference, this head passed the fork's full CI test matrix, macOS included (the first run caught an over-broad assertion that also recorded unrelated sqlite ResourceWarnings; the test now checks only the fork-with-threads warning): https://github.com/marlon-costa-dc/rope/actions/runs/44977474839

This branch has not been deployed

No deployments
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.

1 participant