Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

thread waiting for input survives the end of execution

未關閉
#452 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
45/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
jupyter, python
領域
backend

研究方向

從 ipykernel/kernelbase.py 中的 Kernel._input_request 開始,重現 issue 中的兩個執行緒輸入情境。追蹤執行結束後 stdin_socket 關閉與 self.session.recv 之間的互動;完成標準是,擱置中的執行緒輸入不再卡住,也不再破壞後續的輸入請求。

由索引模型根據 Issue 內容生成。

描述

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'{}'
主要語言
Python
星號
734
分支
411
平均合併
1 天 6 小時
30 天內合併 PR
10

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

ipython/ipykernel 的其他 Issue

查看 ipython/ipykernel 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。