python-trio / python-trio/trio

Maybe make task-local storage work from run_in_worker_thread functions

Open
#178 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

design discussion polish threads
Dominant language
Python
Stars
7.3k
Forks
431
Avg merge
2d 17h
Merged PRs (30d)
6

Description

This is handy for logging, and safe because we know that either the task or the thread is running, but never both - so no locking is needed. But maybe confusing (it can't work for run-locals, or run_in_worker_process)?

What should current_task() return in a run_in_worker_thread function? Currently we effectively find the task-locals by looking up the current task, so the most naive way to make task-locals work would to make current_task() work and then task-locals would work for free. Is that good or bad?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the behavior of current_task() and task-local storage when called from run_in_worker_thread functions, and compare it with run_in_worker_process. Define and verify the intended behavior for task-locals and current_task(), including what should happen in worker-thread and worker-process functions.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.