Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Strange occasional `RuntimeError: Event loop is closed` out of nowhere

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

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend, devtools

Hướng nghiên cứu

Bắt đầu với ipykernel/iostream.py, đặc biệt là _watch_pipe_fd, write, _schedule_flush và đường dẫn scheduling của pub-thread được hiển thị trong traceback. So sánh vòng đời đó với Kernel.do_execute và cách trình thông dịch bên ngoài xử lý stdout và stderr, sau đó điều tra thời điểm vòng lặp asyncio được đóng. Được xem là hoàn tất khi xác định được một race trong quá trình tắt máy có thể tái hiện hoặc xác nhận code của người dùng chịu trách nhiệm, đồng thời thêm một regression test nếu vấn đề nằm trong ipykernel.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

I'm implementing a kernel by inheriting from ipykernel.kernelbase.Kernel, as described at Making simple Python wrapper kernels.

That generally works well, but I have a strange problem: Occasionally I get an exception RuntimeError: Event loop is closed:

Traceback (most recent call last):
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/ipykernel/iostream.py", line 390, in _watch_pipe_fd
    self.write(bts.decode(errors='replace'))
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/ipykernel/iostream.py", line 664, in write
    self._schedule_flush()
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/ipykernel/iostream.py", line 561, in _schedule_flush
    self.pub_thread.schedule(_schedule_in_thread)
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/ipykernel/iostream.py", line 269, in schedule
    f()
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/ipykernel/iostream.py", line 559, in _schedule_in_thread
    self._io_loop.call_later(self.flush_interval, self._flush)
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/tornado/ioloop.py", line 597, in call_later
    return self.call_at(self.time() + delay, callback, *args, **kwargs)
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/site-packages/tornado/platform/asyncio.py", line 206, in call_at
    return self.asyncio_loop.call_later(
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/asyncio/base_events.py", line 721, in call_later
    timer = self.call_at(self.time() + delay, callback, *args,
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/asyncio/base_events.py", line 732, in call_at
    self._check_closed()
  File "/home/ca/Store/micromamba/envs/std/lib/python3.10/asyncio/base_events.py", line 515, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

The traceback does not go back to my code, so I'm not certain whether I did something wrong, or there is a bug in ipykernel.kernelbase? I am unable to reproduce the error, in the exact same situation it sometimes happens and sometimes doesn't.

I found two other issues which mention this exception, but they are about UI events (#825) or parallelization (#534), both of which I do not use. I inherited from ipykernel.kernelbase.Kernel and implemented do_execute, which sends code to an external interpreter and sends its stdout and stderr via self.send_response.

Ngôn ngữ chính
Python
Star
734
Fork
411
Merge trung bình
1 ngày 2 giờ
Pull request đã merge (30 ngày)
9

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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.

Issue khác của ipython/ipykernel

Tất cả issue của ipython/ipykernel

Issue tương tự

Thêm issue về Python

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.