Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python守护进程可以看到数据库,但抱怨表不存在_Python_Sqlite_Python Daemon - Fatal编程技术网

Python守护进程可以看到数据库,但抱怨表不存在

Python守护进程可以看到数据库,但抱怨表不存在,python,sqlite,python-daemon,Python,Sqlite,Python Daemon,我有一个连接到sqlite数据库的普通python 在我尝试将其作为守护进程运行之前,一切都正常。下面是我用来做这件事的代码: def start(self): if self.lockfile.is_locked(): exit_with_code(7, self.pid_file) # If we're running in debug, run in the foreground, else daemonise if self.options['debug']:

我有一个连接到sqlite数据库的普通python

在我尝试将其作为守护进程运行之前,一切都正常。下面是我用来做这件事的代码:

def start(self):
  if self.lockfile.is_locked():
    exit_with_code(7, self.pid_file)

  # If we're running in debug, run in the foreground, else daemonise
  if self.options['debug']:
    try:
      self.main()
    except KeyboardInterrupt:
      pass
    finally:
      self.close_gracefully()
  else:
    context = daemon.DaemonContext(
      files_preserve = [self.logger.socket(), self.lockfile]
    )

    context.signal_map = {
      signal.SIGTERM: self.close_gracefully
    }

    with context: self.main()
我可以在前台使用
python-mstarter-debug
运行它,一切正常,我的应用程序会写入数据库,但当我关闭debug标志时,我在尝试写入时会看到以下内容:

no such table: Frontends
我知道frontends表存在,因为我已经打开了数据库。我假设python正在查找数据库,因为否则会出现完全不同的错误消息

我的所有文件都归vagrant所有,
ls-l
显示以下内容:

-rwxrwxrwx 1 vagrant vagrant 9216 Nov  9 18:09 development.sqlite
有人有什么建议吗

更新

根据要求,这里是我的数据库的代码

import os
import sqlite3

class Database(object):

    def __init__(self, db_file='/vagrant/my_daemon/db/development.sqlite'):

        self.db = sqlite3.connect(db_file)

        if os.path.exists(db_file):
            print "db exists"

当我运行这个程序时,它会打印“db exists”。我通过调用
database()
在starter.py中实例化数据库

Python守护进程在后台监控时关闭所有打开的文件描述符(stdin、stout和stderr除外)

我花了很长时间试图找出哪些文件保持打开状态以防止数据库不可访问,最后我发现在后台程序上下文中初始化数据库比在外部更容易。这样我就不必担心哪些文件应该保持打开状态


现在一切正常。

你的假设可能是错误的。显示试图打开数据库的代码。@CL我更新了我的答案。这两个文件名中哪一个是正确的?@CL正确的文件名是development.sqlite,我更新了问题我想这可能是vagrant/puppet的问题,因为我在syslog中发现了以下内容:
Nov 9 20:44:26 puppet agent[1402]:未收到证书
,我开始认为我的软件包没有正确安装。我要一个全新的虚拟机。