-
Notifications
You must be signed in to change notification settings - Fork 2
PyIsolate Update: Production-Ready Process Isolation for ComfyUI #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Implemented activation scripts for bash, csh, and fish shells. - Created executable scripts for f2py, normalizer, numpy-config, pip, pip3, and python binaries. - Added pyvenv.cfg for virtual environment configuration. - Enhanced client and host modules to support path unification and environment snapshotting. - Introduced path_helpers for managing sys.path in child processes. - Added unit tests for path_helpers to ensure functionality and correctness.
- Implements host sys.path snapshot and child reconstruction - Enables isolated processes to import host modules (e.g., ComfyUI utils) - Adds build_child_sys_path() with smart filtering: * Prepends application root * Filters code subdirectories to prevent shadowing * Preserves host .venv/site-packages * Appends isolated venv packages - Adds serialize_host_snapshot() for environment capture - 18 unit tests with 100% coverage for path_helpers.py - Solves multiprocessing.spawn() import visibility problem Use case: ComfyUI custom nodes need both host modules (folder_paths, utils.*) and isolated dependencies (deepdiff) in same process. Tested with ComfyUI integration - all imports working correctly.
- Add --index-strategy unsafe-best-match for torch dev versions - Enables PyIsolate to work with torch nightlies (e.g., 2.9.0.dev+cu129) - Without this, uv fails when exact dev version unavailable on PyPI - Unblocks 100% of ComfyUI installations using torch nightlies Fixes issue where exact dev build versions don't exist on any index and uv refuses to install without fallback strategy enabled.
…client snapshot handling and extension safety
…nd logging in core components
…infinite recursion in ProxiedSingleton
… path unification
…n; ensure CUDA tensors are handled correctly
…; implement serialization hooks for ModelPatcher
…n; support sharing of PyTorch and optimize link mode handling
… of `logging` python library and those messages being properly transmitted via RPC
Implements CLIPRegistry (ProxiedSingleton) + CLIPProxy for isolated nodes. Handles unpicklable CLIP objects via RPC. Includes ScopedModelRegistry, full test coverage, and automatic CLIP→CLIPRef serialization in execution flow. Deletes rejected logging_proxy.py.
Replace --system-site-packages with site.addsitedir() injection to enable proper parent→child venv inheritance while blocking system Python packages. Architecture: - Child venvs created WITHOUT --system-site-packages (blocks /usr packages) - Write _pyisolate_parent.pth into child's site-packages on creation - .pth file invokes site.addsitedir(parent_site) for recursive .pth processing - Ensures namespace packages and C extensions initialize correctly
…treamline editable and local path handling in dependencies
Problem:
On Windows, multiprocessing.Queue() uses semaphores that cannot be
inherited by child processes when set_executable() changes the Python
interpreter to a different venv. This causes:
PermissionError: [WinError 5] Access is denied
Solution:
Replace direct Queue() with Manager().Queue() which uses TCP sockets
instead of semaphores, avoiding Windows handle inheritance issues.
Key changes in pyisolate/_internal/host.py:
- Use get_context("spawn") instead of set_start_method() for isolation
- Initialize Manager-based queues for cross-venv IPC compatibility
- Set PYISOLATE_CHILD=1 BEFORE Manager() to prevent ComfyUI re-init
- Add proper Manager.shutdown() cleanup in Extension.stop()
- Add os.name=="nt" checks for Windows-specific paths:
- Scripts/python.exe vs bin/python
- Lib/site-packages vs lib/pythonX.Y/site-packages
- VIRTUAL_ENV environment variable injection
Linux compatibility:
- All changes are additive with proper else branches
- Manager queues work on both platforms (negligible overhead)
- Platform-agnostic env var guards
Tested on: Windows 11,
…ct and sequence subclasses, and add safety checks for unpicklable objects
…edundant debug statements
…pynvml deprecation warnings in child processes
…nd enhance proxy handling
… for compatibility with CUDA versions
…ls and path unification explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces PyIsolate v1.0 with production-ready process isolation for ComfyUI. The major changes include full ComfyUI integration with path unification to ensure isolated child processes can access ComfyUI imports, a lazy loading and caching system for zero startup penalty, and Windows compatibility through Manager-based IPC queues. Additional improvements include torch ecosystem support with dynamic package discovery, stateless RPC implementation with callback support, tensor serialization safety features, logging deduplication, comprehensive documentation, and unit tests.
Key Changes:
- Path unification system ensures ComfyUI root is first in sys.path for child processes
- Lazy process spawning with node caching for instant subsequent loads
- Windows-compatible IPC using Manager-based queues instead of POSIX-only Queue
- Dynamic torch ecosystem package discovery for CUDA compatibility
- RPC callback support for bidirectional async communication
Reviewed changes
Copilot reviewed 25 out of 41 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_singleton_shared.py | New test file for singleton and proxied singleton behavior |
| tests/test_path_helpers.py | Tests for sys.path snapshot and reconstruction logic |
| tests/test_extension_safety.py | Tests for extension name normalization and dependency validation |
| tests/test_client_snapshot.py | Tests for client-side snapshot handling and path unification |
| tests/path_unification/test_path_helpers.py | Comprehensive path unification unit tests |
| tests/conftest.py | Added ComfyUI root to sys.path for test compatibility |
| pyproject.toml | Added asyncio_mode configuration for pytest |
| pyisolate/path_helpers.py | New module for host path context sharing and sys.path reconstruction |
| pyisolate/host.py | Lazy loading implementation and improved logging |
| pyisolate/config.py | Dynamic torch ecosystem package discovery |
| pyisolate/_internal/shared.py | RPC callback support and tensor serialization safety |
| pyisolate/_internal/model_serialization.py | Custom serialization for ComfyUI ModelPatcher objects |
| pyisolate/_internal/host.py | Windows Manager-based queues, lazy initialization, torch inheritance |
| pyisolate/_internal/client.py | Module-level path unification and RPC setup |
| comfy_hello_world/* | Example files demonstrating ComfyUI integration |
| benchmark_results_llamatron_*.txt | Benchmark output file |
| SETUP_GUIDE.md | New setup guide for repository |
| README.md | Updated documentation and quick start guide |
Comments suppressed due to low confidence (3)
tests/test_client_snapshot.py:1
- The hardcoded absolute path
/home/johnj/ComfyUIis user-specific and will not work on other machines or CI environments. Consider using a relative path, environment variable, or creating a mock ComfyUI structure in tmp_path for portability.
tests/test_extension_safety.py:1 - The test expects the environment variable to equal the string
"None", but the context manager sets it toNone(the Python object). WhenNoneis passed toos.environ[key] = str(value), it becomes the string"None". This is inconsistent with the comment on line 70 saying "unsets_when_none". Either the test name is misleading or the behavior should actually remove the key when None is passed.
tests/conftest.py:1 - The hardcoded absolute path
/home/johnj/ComfyUIis user-specific. This will break tests on other developer machines and CI environments. Consider using an environment variable with a fallback, or detect the path dynamically.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| valid_parents = [p for p in sys.path if "site-packages" in p and p.startswith(host_prefix)] | ||
|
|
||
| if not valid_parents: | ||
| raise RuntimeError("Could not determine parent site-packages path to inherit") |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message does not provide actionable information for debugging. Consider including details about what paths were checked in valid_parents and what host_prefix was, to help users understand why the detection failed.
| raise RuntimeError("Could not determine parent site-packages path to inherit") | |
| raise RuntimeError( | |
| f"Could not determine parent site-packages path to inherit.\n" | |
| f"host_prefix: {host_prefix}\n" | |
| f"parent_sites: {parent_sites}\n" | |
| f"valid_parents: {valid_parents}" | |
| ) |
| include-system-site-packages = false | ||
| version = 3.12.3 | ||
| executable = /usr/bin/python3.12 | ||
| command = /home/johnj/pyisolate/.venv/bin/python -m venv --copies /home/johnj/pyisolate/comfy_hello_world/node-venvs/simple_text_node |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generated venv configuration file contains hardcoded user-specific paths (/home/johnj/). These files should typically be excluded from version control via .gitignore as they are environment-specific and will not work on other machines.
| ## 2. Bootstrap the repository | ||
|
|
||
| ```bash | ||
| cd /home/johnj/pyisolate |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setup guide uses the hardcoded path /home/johnj/pyisolate which is user-specific. Replace with a generic placeholder like cd /path/to/pyisolate or cd ~/pyisolate to make the guide applicable to all users.
fix(logging): adjust logging level for child processes to suppress duplicate INFO logs
…ving default handlers
PyIsolate Update: Production-Ready Process Isolation for ComfyUI
Major Features
1. Full ComfyUI Integration with Path Unification
Commits:
aee01de,458d11a,846e4cc,8699bfa,029ae2cComfyUI-side:
951a6ba7,a62150a3,230544ac,852251a0,04485daautils.json_utilaccessible in all children2. Lazy Loading & Caching System
Commits:
b4cdd9aComfyUI-side:
1a20f4ac,fe3b402a3. Windows Compatibility
Commits:
dbca9bbComfyUI-side:
8587e20bExpansions
1. Torch Ecosystem Support
Commits:
99e742e,8d83a4b,4baa626,4027e0cshare_torch=True--index-strategy unsafe-best-match(standarduvpattern for non-release version resolution where strict matching fails)2. Stateless RPC Implementation
Commits:
cd07469,846e4cc,d785fa3ComfyUI-side:
6603f42c,d9a5c36c,54784f333. Tensor Serialization Safety
Commits:
28e7018,a54aa19Polish
1. Logging Deduplication
Commits:
fcb2489,e0540f8ComfyUI-side:
2d1bb755,fe3b402a,c80c1dbb2. Documentation
Commits:
029ae2c,f0452103. Unit Tests
Commits:
465c72b,58ba87dTesting
Baseline test: 3 isolated nodes loading in 0.0s (cached), workflow execution in 0.15s
Command:
/home/johnj/mysolate/debug/run_debug.shResult: ✅ PASS
Statistics
Commit range:
16ddb98..029ae2c(27 commits)Lines changed: 59 files, +9194/-194 lines
Authors: John Pollock (pyisolate), ComfyUI-side integration