我在 fedora 27 伺服器上執行 jupyter 4.4.0 筆記本服務(jupyter notebook --no-browser --port 8889),我透過瀏覽器遠端存取該服務。使用該服務幾個小時且沒有出現任何問題後,我收到“內核錯誤”。在最初的幾個小時內,我能夠毫無錯誤地啟動新筆記本。但是,經過一段時間後,我收到下面給出的錯誤訊息。它清楚地告訴我內核錯誤是由於缺少檔案「/run/user/1001/jupyter/kernel-869f88b2-0895-40fb-b759-c518a1686484.json」造成的。
經過進一步調查,我注意到該檔案遺失了,因為 /run/user/1001 中遺失了整個 jupyter 目錄。 jupyter 目錄似乎是在我第一次啟動服務時創建的,然後似乎在一段時間後自動刪除。
經過幾天的搜尋表明,該問題可能是由於不活動造成的,這會導致作業系統或 jupyter 服務刪除 /run/user/1001/jupyter 目錄。
到目前為止,我還無法弄清楚到底是什麼刪除了 /run/user/1001/jupyter 目錄或如何阻止這種情況發生。你知道如何解決這個問題嗎?
錯誤訊息
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/web.py", line 1469, in _execute
result = yield result
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
value = future.result()
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1021, in run
yielded = self.gen.throw(*exc_info)
File "/opt/anaconda3/lib/python3.6/site-packages/notebook/services/sessions/handlers.py", line 73, in post
type=mtype))
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
value = future.result()
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1021, in run
yielded = self.gen.throw(*exc_info)
File "/opt/anaconda3/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 79, in create_session
kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
value = future.result()
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1021, in run
yielded = self.gen.throw(*exc_info)
File "/opt/anaconda3/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 92, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 1015, in run
value = future.result()
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/concurrent.py", line 237, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
File "/opt/anaconda3/lib/python3.6/site-packages/tornado/gen.py", line 285, in wrapper
yielded = next(result)
File "/opt/anaconda3/lib/python3.6/site-packages/notebook/services/kernels/kernelmanager.py", line 160, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "/opt/anaconda3/lib/python3.6/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "/opt/anaconda3/lib/python3.6/site-packages/jupyter_client/manager.py", line 240, in start_kernel
self.write_connection_file()
File "/opt/anaconda3/lib/python3.6/site-packages/jupyter_client/connect.py", line 472, in write_connection_file
kernel_name=self.kernel_name
File "/opt/anaconda3/lib/python3.6/site-packages/jupyter_client/connect.py", line 137, in write_connection_file
with open(fname, 'w') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/run/user/1001/jupyter/kernel-869f88b2-0895-40fb-b759-c518a1686484.json'
謝謝
答案1
我透過設定 JUPYTER_RUNTIME_DIR 變數來解決此問題。 Jupyter 預設將運行時檔案儲存在 $XDG_RUNTIME_DIR/jupyter 中。設定 JUPYTER_RUNTIME_DIR 將覆蓋此行為。您可以將其設定為某個不會自動清理的目錄,以防止此錯誤。
這是我在啟動 jupyter 之前所做的:
export JUPYTER_RUNTIME_DIR="path_to_my_home_directory/.jupyter_runtime"
問題就解決了!
我發現的更多細節:
https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables