🧠 Feature: Context-Aware Task Submission with Thread Zones
Goal:
Allow .submit() to dynamically route tasks based on thread context and user flags like pure_python. This enables hybrid scheduling:
- Pure Python tasks can be migrated/flexibly scheduled
- Unsafe or ambiguous tasks are locked to a dedicated thread
✅ Key Components:
-
ThreadContext
- Thread-local store to track current task info (e.g.
pure_python flag)
-
TaskZone
- Manages scheduling policy (safe thread pool vs locked thread)
-
SmartSubmitter
.submit() wrapper that:
- Reads current thread context
- Applies defaults and inheritance rules
- Supports
force_detach for safe overrides
🔐 Core Rules
| Situation |
Behavior |
| No context (external submit) |
Uses provided pure_python flag (default: False) |
Inside pure_python=False thread |
Inherit locked context unless forced |
Inside pure_python=True thread |
Use fast pool unless user disables |
force_detach=True |
Force route to chosen pool, skip inheritance |
🧩 Example Usage
factory.submit(my_task, pure_python=True) # Can move across threads
factory.submit(blocking_task) # Locked by default
factory.submit(lightweight, pure_python=True, force_detach=True) # Override context
💡 Bonus: Validation Hook
Warn if a task is flagged pure_python=True but fails safety checks:
if pure_python and not validate_func_safety(func):
warn(f"Function {func.__name__} flagged pure but appears unsafe")
🛠 Tasks To Do
This system is a flexible and scalable foundation for ThreadFactory’s intelligent scheduling pipeline.
🧠 Feature: Context-Aware Task Submission with Thread Zones
Goal:
Allow
.submit()to dynamically route tasks based on thread context and user flags likepure_python. This enables hybrid scheduling:✅ Key Components:
ThreadContextpure_pythonflag)TaskZoneSmartSubmitter.submit()wrapper that:force_detachfor safe overrides🔐 Core Rules
pure_pythonflag (default: False)pure_python=Falsethreadpure_python=Truethreadforce_detach=True🧩 Example Usage
💡 Bonus: Validation Hook
Warn if a task is flagged
pure_python=Truebut fails safety checks:🛠 Tasks To Do
ThreadContext(thread-local storage)SmartSubmitterlogicsubmit()calls via context-aware resolverforce_detach=Trueoverridevalidate_func_safety()to detect C-extension callsThis system is a flexible and scalable foundation for ThreadFactory’s intelligent scheduling pipeline.