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

thread waiting for input survives the end of execution

Đang mở
#452 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.

Đá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
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
jupyter, python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu trong ipykernel/kernelbase.py tại Kernel._input_request và tái hiện cả hai kịch bản nhập liệu trong thread từ issue. Theo dõi cách việc đóng stdin_socket và self.session.recv tương tác sau khi thực thi kết thúc; hoàn thành khi một yêu cầu nhập liệu đang chờ trong thread không còn bị treo hoặc làm hỏng một yêu cầu nhập liệu tiếp theo.

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

Mô tả

If a thread asks for input after the end of execution, it will crash as expected. If it asks for input before the end of execution, it will hang in a strange state that will crash ipykernel as soon as another input request is sent.

The offending line is: self.session.recv(self.stdin_socket, 0) in kernelbase.Kernel._input_request. If stdin_socket.close() is called before recv, it will crash. If stdin_socket.close() is called after self.session.recv(self.stdin_socket, 0), it will hang forever.

Ask after end
In [1]: import threading
   ...: import time
   ...: 
   ...: def getinput():
   ...:     time.sleep(1)
   ...:     print(input('thread:'))
   ...: 
   ...: thread = threading.Thread(target=getinput)
   ...: thread.start()
   ...: time.sleep(0.5)
thread:Exception in thread Thread-12:
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "<ipython-input-1-2acffc6600f3>", line 6, in getinput
    print(input('thread:'))
EOFError: EOF when reading a line


In [2]: print(input('main:'))

main:test
test

In [3]: 
Ask before end
In [1]: import threading
   ...: import time
   ...: 
   ...: def getinput():
   ...:     time.sleep(0.5)
   ...:     print(input('thread:'))
   ...: 
   ...: thread = threading.Thread(target=getinput)
   ...: thread.start()
   ...: time.sleep(1)

thread:

In [2]: print(input('main:'))

main:hi
[IPKernelApp] WARNING | Invalid Message:
Traceback (most recent call last):
  File "/Users/quentinpeter/pyscripts/ipykernel/ipykernel/kernelbase.py", line 884, in _input_request
    ident, reply = self.session.recv(self.stdin_socket, 0)
  File "/usr/local/lib/python3.7/site-packages/jupyter_client/session.py", line 835, in recv
    idents, msg_list = self.feed_identities(msg_list, copy)
  File "/usr/local/lib/python3.7/site-packages/jupyter_client/session.py", line 866, in feed_identities
    idx = msg_list.index(DELIM)
ValueError: b'<IDS|MSG>' is not in list
[IPKernelApp] WARNING | Invalid Message:
Traceback (most recent call last):
  File "/Users/quentinpeter/pyscripts/ipykernel/ipykernel/kernelbase.py", line 884, in _input_request
    ident, reply = self.session.recv(self.stdin_socket, 0)
  File "/usr/local/lib/python3.7/site-packages/jupyter_client/session.py", line 840, in recv
    raise e
  File "/usr/local/lib/python3.7/site-packages/jupyter_client/session.py", line 837, in recv
    return idents, self.deserialize(msg_list, content=content, copy=copy)
  File "/usr/local/lib/python3.7/site-packages/jupyter_client/session.py", line 945, in deserialize
    raise ValueError("Invalid Signature: %r" % signature)
ValueError: Invalid Signature: b'{}'
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.