V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
graetdk
V2EX  ›  问与答

几百块找大佬解决一个小问题

  •  
  •   graetdk · 2020-08-02 09:52:27 +08:00 · 3571 次点击
    这是一个创建于 1579 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我使用开源 BI 工具 Superset 搭了一个业务看板,其它方面没得说,确实挺棒的

    但就是有一个问题:在每次进入 Dashboard 的时候,会出现这样的报错:

    需要刷新很多次才能好

    完整报错代码如下:

       Traceback (most recent call last):
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 755, in _commit_impl
        self.engine.dialect.do_commit(self.connection)
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 534, in do_commit
        dbapi_connection.commit()
    sqlite3.OperationalError: database is locked
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/flask/app.py", line 2446, in wsgi_app
        response = self.full_dispatch_request()
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/flask/app.py", line 1951, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/flask/app.py", line 1820, in handle_user_exception
        reraise(exc_type, exc_value, tb)
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
        raise value
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/flask/app.py", line 1949, in full_dispatch_request
        rv = self.dispatch_request()
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/flask/app.py", line 1935, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/flask_appbuilder/security/decorators.py", line 109, in wraps
        return f(self, *args, **kwargs)
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/superset/views/core.py", line 1796, in dashboard
        edit_mode=edit_mode,
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/superset/utils/log.py", line 78, in wrapper
        referrer=referrer,
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/superset/utils/log.py", line 161, in log
        sesh.commit()
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/orm/scoping.py", line 162, in do
        return getattr(self.registry(), name)(*args, **kwargs)
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 1036, in commit
        self.transaction.commit()
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 507, in commit
        t[1].commit()
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1727, in commit
        self._do_commit()
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1758, in _do_commit
        self.connection._commit_impl()
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 757, in _commit_impl
        self._handle_dbapi_exception(e, None, None, None, None)
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1476, in _handle_dbapi_exception
        util.raise_from_cause(sqlalchemy_exception, exc_info)
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
        reraise(type(exception), exception, tb=exc_tb, cause=cause)
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 152, in reraise
        raise value.with_traceback(tb)
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 755, in _commit_impl
        self.engine.dialect.do_commit(self.connection)
      File "/root/.pyenv/versions/3.6.5/envs/venv-3.6.5/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 534, in do_commit
        dbapi_connection.commit()
    sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked
    (Background on this error at: http://sqlalche.me/e/e3q8)
    

    初步判断是 sqlite3 的问题,在读数据库的时候遇到锁了,但是咱 python 太菜了,不知道有什么好的方法可以改一下(例如增加等待时间啥的)

    因此希望求助各位大佬,能解决的给一个大红包,拜谢了

    第 1 条附言  ·  2020-08-02 10:31:34 +08:00
    联系方式:Z3JlYXRkaw== (微信)
    14 条回复    2020-10-26 10:31:38 +08:00
    huabalance
        1
    huabalance  
       2020-08-02 10:00:04 +08:00
    如果数据很多,并发也多的话,sqlite 不算是好的数据库。。
    lxk11153
        2
    lxk11153  
       2020-08-02 10:03:48 +08:00
    加锁?加 TM de
    huabalance
        3
    huabalance  
       2020-08-02 10:04:41 +08:00
    可以留下你的联系方式。。
    graetdk
        4
    graetdk  
    OP
       2020-08-02 10:31:14 +08:00
    @huabalance 微信 Z3JlYXRkaw==
    imn1
        5
    imn1  
       2020-08-02 10:56:29 +08:00
    加个参数? check_same_thread=False
    不过用的是 sqlalchemy,那我也不清楚了
    jakezh
        6
    jakezh  
       2020-08-02 11:09:23 +08:00
    楼主帮你省几百块钱 touch your_path/superset.db
    graetdk
        7
    graetdk  
    OP
       2020-08-02 11:31:05 +08:00
    @jakezh 这个文件在哪个目录下面啊?
    barrelsoil
        8
    barrelsoil  
       2020-08-02 11:53:02 +08:00
    @graetdk find 啊
    graetdk
        9
    graetdk  
    OP
       2020-08-02 12:47:08 +08:00
    @jakezh
    @barrelsoil

    木有找到这个文件
    liprais
        10
    liprais  
       2020-08-02 12:49:15 +08:00
    别用 sqlite 呗
    renmu123
        11
    renmu123  
       2020-08-02 13:09:41 +08:00 via Android
    lasuar
        12
    lasuar  
       2020-08-03 13:51:38 +08:00
    切 mysql 可解
    Neenjage
        13
    Neenjage  
       2020-10-25 18:26:34 +08:00
    楼主,你好,我也是 superset 遇到这个问题了,每次第一次访问 dashboard 基本就会有这个问题,楼主解决问题了吗,分享下
    graetdk
        14
    graetdk  
    OP
       2020-10-26 10:31:38 +08:00
    @Neenjage 没有,我现在用最粗暴的办法,开一个 supervisor,遇到这个报错就 restart 整个 superset,这样刷新后就能正常进入报表
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1028 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 21:32 · PVG 05:32 · LAX 13:32 · JFK 16:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.