我正在使用分布式文件系统的计算机集群上运行Jupyter笔记本电脑。
一段时间后,由于出现错误,我无法打开新笔记本:
Close without saving?
File "XXX.ipynb" has unsaved changes, close without saving?
查看Jupyter日志,我发现由于nbsignatures.db
数据库被锁定而导致了该错误。
[E 15:58:01.190 LabApp] Uncaught exception GET /api/contents/workspace/proteinsolver/notebooks/XXX.ipynb?type=notebook&content=1&1572638276143 (10.74.73.2)
HTTPServerRequest(protocol='http', host='localhost:9416', method='GET', uri='/api/contents/workspace/proteinsolver/notebooks/04_sudoku_train-01-Copy8.ipynb?type=notebook&content=1&1572638276143', version='HTTP/1.1', remote_ip='10.74.73.2')
Traceback (most recent call last):
File "/home/username/miniconda3/lib/python3.7/site-packages/tornado/web.py", line 1699, in _execute
result = await result
File "/home/username/miniconda3/lib/python3.7/site-packages/tornado/gen.py", line 209, in wrapper
yielded = next(result)
File "/home/username/miniconda3/lib/python3.7/site-packages/notebook/services/contents/handlers.py", line 112, in get
path=path, type=type, format=format, content=content,
File "/home/username/miniconda3/lib/python3.7/site-packages/notebook/services/contents/filemanager.py", line 433, in get
model = self._notebook_model(path, content=content)
File "/home/username/miniconda3/lib/python3.7/site-packages/notebook/services/contents/filemanager.py", line 392, in _notebook_model
self.mark_trusted_cells(nb, path)
File "/home/username/miniconda3/lib/python3.7/site-packages/notebook/services/contents/manager.py", line 508, in mark_trusted_cells
trusted = self.notary.check_signature(nb)
File "/home/username/miniconda3/lib/python3.7/site-packages/nbformat/sign.py", line 439, in check_signature
return self.store.check_signature(signature, self.algorithm)
File "/home/username/miniconda3/lib/python3.7/site-packages/nbformat/sign.py", line 232, in check_signature
""", (algorithm, digest)).fetchone()
sqlite3.OperationalError: database is locked
对我来说,最简单的解决方法是什么?
答案 0 :(得分:2)
笔记本是否有可能被保存在git中并且存在合并冲突?查看此解决方案:https://stackoverflow.com/a/61031136/4001214修复了我遇到的问题。
当git无法解决文本文件中的冲突时,它将其合理的差异想法放入文件中。这会破坏.ipynb的JSON结构,并使它在jupyter中不可读。在链接的解决方案中,作者显示
<<<<<<< HEAD
},
{
<CONTENTS OF MY CELL>
]
=======
>>>>>>> a23f8f8f9db0974b7de90c6e7ed8599fa04d53cc
,并注意到使用文本编辑器从文件中删除有问题的行可以解决此问题。就我而言,我在git中有一个已知的好文件,因此我删除了本地副本并重新拉了。
答案 1 :(得分:0)
Jupyter使用SQLite数据库编写笔记本签名,as reported previously表示SQLite在分布式文件系统上表现不佳。
首先,我们需要生成一个Jupyter配置文件(默认情况下未创建):
jupyter notebook --generate-config
然后,我们需要编辑此配置文件(jupyter_notebook_config.py
),以将默认SQLite存储引擎设置为:memory:
:
c.NotebookNotary.db_file = ':memory:'
打开新笔记本将不再需要调用数据库!