Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

thread waiting for input survives the end of execution

オープン
#452 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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日 2時間
マージ済み PR(30日)
9

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ipython/ipykernel のほかの issue

ipython/ipykernel の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。