English 中文(简体)
使用气瓶-zodb 的锁定错误
原标题:LockError using flask-zodb

I have a problem using flask-zodb in a simple Flask app deployed with mod_wsgi. Every time I try to use the DB for example setting defaults:

from flaskext.zodb import zodb, List

db = ZODB(app)
app.config.from_pyfile( settings.py ) # here I have defined ZODB_STORAGE = "/home/username/webapps/myapp/htdocs/Data.fs"

@app.before_request
def set_db_defaults():
   if  entries  not in db:
       db[ entries ] = List()

或者在类似:

@app.route( /add , methods=[ POST ])
def add_entry():
   db[ entries ].append(request.form)
   flash( New entry was successfully posted )
   return redirect(url_for( show_entries ))

我犯了以下错误:

[Sat May 19 16:52:30 2012] [error] [client 127.0.0.1]
self._lock_file = LockFile(file_name +  .lock )
[Sat May 19 16:52:30 2012] [error] [client 127.0.0.1]   File
"/home/userame/.virtualenvs/myapp/lib/python2.7/site-packages/zc/lockfile/__init__.py",
line 76, in __init__
[Sat May 19 16:52:30 2012] [error] [client 127.0.0.1]     _lock_file(fp)
[Sat May 19 16:52:30 2012] [error] [client 127.0.0.1]   File
"/home/username/.virtualenvs/myapp/lib/python2.7/site-packages/zc/lockfile/__init__.py",
line 59, in _lock_file
[Sat May 19 16:52:30 2012] [error] [client 127.0.0.1]     raise
LockError("Couldn t lock %r" % file.name)
[Sat May 19 16:52:30 2012] [error] [client 127.0.0.1] LockError:
Couldn t lock  /home/username/webapps/myapp/htdocs/Data.fs.lock 

应用软件在开发令人羡慕的状态中运作良好, 我不认为有前意识问题, 因为我想设置:

ZODB_STORAGE = "/tmp"

也提出了同样的例外。我不明白为什么会发生这种情况以及如何避免这种错误。有什么想法吗?

最佳回答

您试图从多个进程打开 ZODB; 开发过程中您可能只使用一个 WSGI 进程。 这基本上是< a href=> https:// stackoverflow. com/ questions/5128807/ zc- lockfile- lockerror- in- zodb>> zc. lockfile. LockError in ZODB 的代号。

您的选项是 :

  1. 生产环境仅限于一个过程。

  2. 使用ZEO,见参考问题;zodburi等同 zeo://localhost:9100

  3. 使用 relStorage 。 您可以使用 < a href=" http://zodburi.readthedocs.org/ en/ latest/ #zconfig- uri- scheme" rel= “ nofollow noreferr” {{Config URI 计划 < /a> 连接, 只要有 relStorage 蛋可用。 这一点在 < a href=> http://pypi. python.org/pypi/ RelStorage#conforiging- repoze-zodbconn> > 的 Rel= nofoltrer > old repoze.zodbcon name < a > 下记录下来。

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签