SQLAlchemy Core插入使得(金字塔)范围的会话挂起(SQLAlchemy Core inserts make (Pyramid) scoped session hanging)
我有很多子对象要添加到父SQA对象,有时10,000左右。 代码在Pyramid应用程序中运行,该应用程序使用作用域会话和
ZopeTransactionExtension
:DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
这没有问题:
lines = [{'col1':1, 'col2':2, 'related_id':1}, ...] for d in lines: d['related_id'] = related_id f = SQAObject(**d) DBSession.add(f)
为了性能,我使用SQLAlchemy Core
insert
重写了这个:lines = [{'col1':1, 'col2':2, 'related_id':1}, ...] rbrf_table = SQAObject.__table__ eng = DBSession.get_bind() conn = eng.connect() for d in lines: d['related_id'] = related_id conn.execute(rbrf_table.insert().values(lines)) conn.close() eng.dispose()
这会导致一个相当奇怪的问题:代码执行(更快),但HTTP请求完成后,结果不会返回给HTTP客户端。 相反,Python进程会无限期地持续占用100%的CPU(我等了半个小时,以确定它是否在任何时间完成)。
我检查了Postgres锁,以确保它们不会阻止它以及活动(
select * from pg_stat_activity
),但似乎没有任何异常。可能是这个问题的原因是什么?
PS怀疑配置一个引擎可能会导致这个问题,我运行相同的代码有和没有
eng.dispose()
,具有相同的结果。UPDATE
情节变浓了。 如果我执行单个插入,它可以工作:
rbrf_table = RTABomRowFile.__table__ eng = DBSession.get_bind() conn = eng.connect() for d in lines: ... ins = rbrf_table.insert().values(d) conn.execute(ins) conn.execute('COMMIT') conn.close() eng.dispose()
I have lots of child objects to add to a parent SQA object, sometimes 10,000 or so. The code runs in Pyramid app, which makes use of scoped session and
ZopeTransactionExtension
:DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
This works without a problem:
lines = [{'col1':1, 'col2':2, 'related_id':1}, ...] for d in lines: d['related_id'] = related_id f = SQAObject(**d) DBSession.add(f)
For performance I rewrote this using SQLAlchemy Core
insert
s:lines = [{'col1':1, 'col2':2, 'related_id':1}, ...] rbrf_table = SQAObject.__table__ eng = DBSession.get_bind() conn = eng.connect() for d in lines: d['related_id'] = related_id conn.execute(rbrf_table.insert().values(lines)) conn.close() eng.dispose()
This causes a rather weird problem: the code executes (faster), but after HTTP request is finished, the result is not returned to HTTP client. Instead the Python process keeps consuming 100% CPU indefinitely (I waited half an hour to make sure if it completes in any time).
I checked Postgres locks to make sure they do not block it as well as activity (
select * from pg_stat_activity
), but there does not seem to be anything unusual.What might be the cause of this problem?
P.S. Suspecting that disposing an engine might cause this problem, I've ran the same code with and without
eng.dispose()
, with the same result.UPDATE
The plot thickens. If I execute individual inserts instead, it works:
rbrf_table = RTABomRowFile.__table__ eng = DBSession.get_bind() conn = eng.connect() for d in lines: ... ins = rbrf_table.insert().values(d) conn.execute(ins) conn.execute('COMMIT') conn.close() eng.dispose()
原文:https://stackoverflow.com/questions/33692443
最满意答案
使用U2U而不是另一个软件,我能够通过删除和移动AND来解决我的问题。
Using U2U instead of another piece of software I was able to solve my problem by removing and moving the AND.
相关问答
更多-
只需遵循SQL示例......外部和三件事情:Bill Cycle测试,and'ed状态测试和OR块。
Bill Cycle 在CAML中相当于SQL IN(SQL IN equivalent in CAML)[2021-12-03]
不,你需要处理嵌套的OR标签; 这些都支持CAML上的查询指令 也许CAML.NET可以帮助你完成任务。 NO, you'll need to deal with nested OR tags; these are supported query instructions on CAML Maybe CAML.NET can help you in your quest.我无法将变量与SPservices中的字符串String进行比较(I can not compare a variable with a string String in SPservices)[2021-10-03]
使用 Nombre_Grup = $(this).attr("Name").trim(); 删除字段中的任何周围空白。 Use Nombre_Grup = $(this).attr("Name").trim(); to remove any surrounding whitespace in the field.我确实找到了一种方法,我认为这可能是http://spservices.codeplex.com/的问题,或者至少,这是我最终得到答案的地方。 我只是在这里发布,以防其他人需要帮助。 它与“查找”标志的查询中的项有关。 查询需要格式化如下: var Query = "" + " " + " " + " caml查询以获取sharepoint 2013上最受欢迎的文档?(caml query to get most popular documents on sharepoint 2013?)[2023-04-04]
您可以在NumberOfLikes上使用orderbyquery,这样您就可以获得最大的文档。 如果你想要一个有限数量的文件然后你可以设置一个query.rowlimit或如果你有像5这样的条件然后你可以使用所述文件gt> 5喜欢按喜欢的顺序 You can user orderbyquery on NumberOfLikes this way you will get document on maximum like on the top. If you want a limited number of ...尝试 另外,抓取一个A CAML构建器工具的副本...... Try"+folderIDtoFind+" ..."+folderIDtoFind+" 我最终用标准的ajax调用替换了SPServices。 这非常有效。 $.ajax({ url: "/_api/lists/getbytitle('User Information List')/items?$filter=Title eq '" + employeeName + "'&$select=Department,JobTitle", type: "GET", async: false, success: function (xml) { department = $(xm ...SPServices将无法加载(SPServices will not load)[2023-05-23]
可能有几个问题: 路径可能无法正确解析(有时相对URL似乎无法在SharePoint上下文中正常工作) 在例如SharePoint webpart中在Javascript中使用jQuery时,尝试在使用SP-Services之前使用jQuery.noConflict()。 在大多数情况下,由于SharePoint中已加载的JQuery,我遇到了使用$或jQuery的问题。 在SharePoint $(document).ready中使用javascript可能会导致问题,因为这实际上并不意味着所有内容都已加 ...使用U2U而不是另一个软件,我能够通过删除和移动AND来解决我的问题。 Using U2U instead of another piece of software I was able to solve my problem by removing and moving the AND.相关文章
更多- [How to] Make custom search with Nutch(v 1.0)?(转)
- sqlalchemy、storm和web2py dal的比较报告
- solr.xml 之core
- Hadoop core之IO
- Solr4.7.2启动时的Index locked for write for core问题分析
- 关于session
- merge solr index &&&&& very import create new core
- org.apache.solr.common.SolrException: No such core: core0
- 通过SolrJ 4.9管理Solr core
- solr在Linux上配置多个core
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)