agronholm / agronholm/anyio

Logging to stdout from anyio worker processes

未关闭
#516 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
2.5k
派生
260
平均合并
2 天 8 小时
30 天内合并 PR
19

描述

We wanted to use `anyio.to_process.run_sync` in order to execute CPU intensive code in worker processes, and we want to emit logs from the code executed by the worker processes. AnyIO uses the stdout/stderr of the worker processes for internal purposes to communicate with the parent process, which means we need another way to write to main process stdout from the worker process without race conditions, or an alternative way to write logs from inside Docker.

**Alternatives examined without changes to AnyIO**

1. os.dup the parent process stdout file descriptor and pass that file descriptor to the worker process. This will not work as expected since there can be race conditions if both the parent process and worker process write logs at the same time to the parent's stdout even via different file descriptors.
2. Write to Docker logs without using writing to stdout/stderr - we didn't find a way to do it, if you know any that will be appreciated.

**Change proposal to AnyIO**
Instead of hard-coding stdout/stdin as the communication mechanism between parent process and child process, allow AnyIO users to opt into another piping mechanism so stdout can still be used in the child process for e.g. logging purposes inside Docker.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。