我有一个连接到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 -m starter -debug在前台运行它,一切正常,我的应用程序会写入数据库,但当我关闭调试标志时,当我尝试写入时,我看到了以下情况:
^{pr2}$
我知道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”。我在中实例化数据库starter.py调用Database()。在