MagicStack / MagicStack/uvloop

echoclient.py fails on recent MacOS and Linux Python releases that default to the spawn start‑method

Đang mở
#735 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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ả

Recent Python releases on macOS and Linux use the `spawn` start‑method by default for new processes.

IIRC spawn starts a brand‑new interpreter and imports the target module it relies on pickling to transport the target function.

As only module‑level objects can be pickled and `run_test` is defined inside the if `__name__ == "__main__"` block, the child process tries to unpickle and look up as an attribute of the module `__mp_main__`. That attribute does not exist, and the unpickler raises:

```
Process ForkServerProcess-2:
File "/usr/lib/python3.14/multiprocessing/process.py", line 320, in _bootstrap
self.run()
~~~~~~~~^^
File "/usr/lib/python3.14/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.14/concurrent/futures/process.py", line 242, in _process_worker
call_item = call_queue.get(block=True)
File "/usr/lib/python3.14/multiprocessing/queues.py", line 120, in get
return _ForkingPickler.loads(res)
~~~~~~~~~~~~~~~~~~~~~^^^^^
AttributeError: module '__mp_main__' has no attribute 'run_test'
```

I am not filing a pull request because there are at least three fixes, and which one is implemented depends on the project team's preferences.

The options I see that fit the file's stated _minimal changes_ from upstream constraint:

1. Move `run_test` to the module level.
2. As this is I/O bound, change to the `ThreadPoolExecutor`
3. Force the use of `fork()`

```python
import multiprocessing
multiprocessing.set_start_method('fork', force=True)
```

All three options seem to benchmark close to each other on Linux/MacOS. Personally I lean towards the `ThreadPoolExecutor` option as that is my personal default for I/O bound concurrent operations.

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với echoclient.py, đặc biệt là định nghĩa run_test bên trong khối __main__ và phần thiết lập process pool của nó. Xem xét ba phương án được đề xuất dựa trên ràng buộc của dự án về việc chỉ thực hiện các thay đổi tối thiểu, sau đó chạy client trên một bản phát hành Python bằng spawn để xác nhận rằng lỗi đã được khắc phục mà không thay đổi hành vi dự kiến của nó.

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
testing
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.