Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Jan 15, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Fixed pickling behavior for SemLock objects. Attempting to serialize a SemLock instance directly now properly raises an error. Users must utilize the multiprocessing.SemLock wrapper to enable serialization support for these objects.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

A new __reduce__ method is added to the SemLock class in the multiprocessing module. This method raises a TypeError to prevent direct pickling of SemLock objects, requiring users to use the appropriate multiprocessing.SemLock wrapper for serialization support instead.

Changes

Cohort / File(s) Summary
SemLock pickling restriction
crates/stdlib/src/multiprocessing.rs
Added __reduce__ method to SemLock class that raises TypeError with message "cannot pickle 'SemLock' object" to block direct serialization

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • RustPython/RustPython#6542: Modifies the core SemLock implementation in multiprocessing module; this PR complements it by adding pickle prevention via the __reduce__ method.

Poem

🐰 A lock that cannot be pickled sweet,
No brines nor jars shall make it neat,
For SemLock stays locked away,
Wrap it well, the proper way! 🔒

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'reject SemLock reduce' directly and specifically describes the main change: preventing SemLock objects from being pickled by implementing a reduce method that rejects serialization.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 609dbb1 and 5697ab3.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_concurrent_futures/test_process_pool.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/stdlib/src/multiprocessing.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style using cargo fmt to format Rust code
Always run clippy to lint code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust

Files:

  • crates/stdlib/src/multiprocessing.rs
🔇 Additional comments (1)
crates/stdlib/src/multiprocessing.rs (1)

550-555: LGTM!

The __reduce__ method correctly prevents direct pickling of SemLock objects by raising a TypeError. This is consistent with CPython's behavior and the existing _rebuild classmethod design pattern—the higher-level multiprocessing.synchronize.SemLock wrapper is expected to handle serialization while using _rebuild for reconstruction.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@youknowone youknowone marked this pull request as ready for review January 16, 2026 01:14
@youknowone
Copy link
Member Author

ran 10 times, no problem

@youknowone youknowone merged commit 746e71a into RustPython:main Jan 16, 2026
13 checks passed
@youknowone youknowone deleted the semlock-pickle branch January 16, 2026 01:18
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