带 Pyramid 的独立 web2py-DAL - 请求、线程和内存
我正在 Pyramid 框架上构建一个应用程序,并希望使用 web2py-DAL 。 Firebird 嵌入式数据库是首选数据库。
在我尝试从一个网页异步调用多个视图之前,这非常有效。 kinterbasdb 驱动程序会出现不同的错误,例如“无效的游标状态”、“无效的游标引用”或“尝试重新关闭已关闭的游标”,其中 sqlite 会崩溃,没有任何错误消息,并会使用 python。这些视图可调用函数除了通过 SELECTing 进行简单读取之外什么也不做。
当金字塔根工厂为每个请求返回相同的 DAL 对象时,就会发生这种情况。似乎形成不同请求的线程正在使用相同的游标对象,因此游标被关闭,而另一个线程假设游标位于此处。
如果我在每个请求上创建一个新的 DAL 对象,则会遇到另一个问题 - 每个请求上的每个新连接都会分配内存,并且该内存不会被释放。因此,在一些讲解员请求后,有数百 MB 的内存被浪费。
不幸的是 Sqlalchemy 不适合这个项目。
有什么想法吗?
I'm building an app on Pyramid framework and would like to use the web2py-DAL with it. Firebird-embedded is the database of choice.
That works great until I try to call multiple views from one web page asynchronously. Different errors like "Invalid cursor state", "Invalid cursor reference" or "Attempt to reclose a closed cursor" are coming up from the kinterbasdb driver where sqlite just breaks down without any error messages and takes python with it. These view callables are doing nothing but simple reads by SELECTing.
This happens in the case that pyramids root factory returns the same DAL object with each request. It seems like threads form different requests are working with the same cursor object, so the cursor gets closed while the other thread assumes the cursor to be here.
If I create a new DAL object on each request I get an other problem - every new connection on each request allocates memory and this memory doesn't get free. So after some docents requests there are some hundred MB wasted memory.
Unfortunately Sqlalchemy is not an option for this project.
Are there any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要点是 DAL 对象应该在每个请求上创建。但之后必须手动关闭。
我是这样做的:
请求对象有一个属性,因此我以这种方式扩展了 DAL 对象:
然后 root_factory 在每个请求上返回一个新的根对象。
感谢 web2py-users 群组!
The point was that the DAL object should be created on every request. But after that it must be closed manually.
I did it in that way: There is a
property of the request object, so I extended the DAL object in that way:
A new Root-object is then returned by the root_factory on each request.
Thanks to the web2py-users group!
web2py 邮件列表中的一些解决方案。
Some solutions from the web2py mailing list.