MagicStack / MagicStack/uvloop
uvloop runs at_fork hook when running subprocess
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Cython
- Star
- 11.9k
- Fork
- 616
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
Speaking about `os.register_at_fork` python docs [explicitly state](https://docs.python.org/dev/library/os.html#os.register_at_fork):
> These calls are only made if control is expected to return to the Python interpreter. A typical [subprocess](https://docs.python.org/dev/library/subprocess.html#module-subprocess) launch will not trigger them as the child is not going to re-enter the interpreter.
The standard `asyncio` loop behaves this way. But `uvloop` doesn't. Repro:
```python
import asyncio
import os
import uvloop
def hook():
os.write(2, b"TRIGGERED\n")
async def run():
process = await asyncio.create_subprocess_exec(
"uptime",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
start_new_session=True
)
stdout, stderr = await process.communicate()
print(f"STDOUT: {stdout.decode('utf-8').strip()}")
if __name__ == "__main__":
os.register_at_fork(after_in_child=hook)
print("asyncio")
asyncio.run(run())
print("uvloop")
uvloop.install()
asyncio.run(run())
```
Output:
```
asyncio
STDOUT: 16:56:42 up 35 days, 6:20, 1 user, load average: 5.21, 4.34, 4.27
uvloop
TRIGGERED
STDOUT: 16:56:42 up 35 days, 6:20, 1 user, load average: 5.21, 4.34, 4.27
```
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách theo dõi cách uvloop xử lý asyncio.create_subprocess_exec và đường dẫn fork được sử dụng sau uvloop.install(), đồng thời so sánh với event loop asyncio tiêu chuẩn và hành vi của os.register_at_fork. Chạy lại reproduction được cung cấp với subprocess uptime; hoàn tất khi hook after_in_child không được kích hoạt đối với lần khởi chạy subprocess này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- operating-systems
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 58/100