如何限制堆大小?(How to limit the heap size?)
我有时会写Python程序,这很难确定在执行前将使用多少内存。 因此,我有时会调用一个Python程序来尝试分配大量的内存,从而使内核严重交换并降低其他正在运行的进程的性能。
因此,我希望限制Python堆可以增长多少内存。 当达到极限时,程序可能会崩溃。 最好的方法是什么?
如果重要的话,很多代码都用Cython编写,所以它应该考虑到在那里分配的内存。 我没有结婚到一个纯粹的Python解决方案(它不需要便携式),所以在Linux上工作的任何事情都很好。
I sometimes write Python programs which are very difficult to determine how much memory it will use before execution. As such, I sometimes invoke a Python program that tries to allocate massive amounts of RAM causing the kernel to heavily swap and degrade the performance of other running processes.
Because of this, I wish to restrict how much memory a Python heap can grow. When the limit is reached, the program can simply crash. What's the best way to do this?
If it matters, much code is written in Cython, so it should take into account memory allocated there. I am not married to a pure Python solution (it does not need to be portable), so anything that works on Linux is fine.
原文:https://stackoverflow.com/questions/2308091
最满意答案
你不能只是“链接”选择功能吗? 喜欢:
Element link = doc.select("div.xpns").select("div.ptctainer").select("div.ptitle").select("p.ptypead").select("span.rtext");
Can't you just 'chain' the selection functions? Like:
Element link = doc.select("div.xpns").select("div.ptctainer").select("div.ptitle").select("p.ptypead").select("span.rtext");
相关问答
更多-
你不能只是“链接”选择功能吗? 喜欢: Element link = doc.select("div.xpns").select("div.ptctainer").select("div.ptitle").select("p.ptypead").select("span.rtext"); Can't you just 'chain' the selection functions? Like: Element link = doc.select("div.xpns").select("div.ptctai ...
-
for循环的问题是你需要使用循环索引 。 循环索引是每次循环即将开始时都会更新的变量。 for循环的工作原理是你有一个代码体,它包含在for循环中,可以执行预定的次数。 for循环的通常格式如下: for idx = array ... %// BODY ... end for循环体内的代码执行的次数与数组中array的长度一样多。 另外, idx是我正在讨论的循环索引 。 具体来说,第一次执行for循环时, idx将等于array的第一个元素。 for循环第二次执行时, idx将等于a ...
-
使用DOMDocument最简单的方法之一是在DOMXPath的帮助下。 从字面上理解你的问题: 我怎样才能遍历办公室的所有孩子:文字? 这可以表示为XPath表达式 : //office:text/child::node() 但是你在这里使用了一些错误的措辞。 它不仅是所有的孩子,还有孩子的孩子等等 - 这些都是后代 : //office:text/descendant::node() 或者使用缩写语法: //office:text//node() 比较: XPath获取所有ChildNodes而不 ...
-
您可以使用.next()来获取类displayAvatar的紧随其后的兄弟: $('.getName').each(function (e) { var techieFullName = $(this).text(); var getNameAcronym = techieFullName.match(/\b(\w)/g); var theName = getNameAcronym.join(''); $(this).next(".displayAvatar").text(t ...
-
当循环遍历DOM时,我如何检查是否到达了body元素?(when looping through the DOM how do I check if I reached the body element?)[2022-05-06]
您可以尝试使用jQuery的.closest()方法,而不是自己进行遍历。 所以我认为你可以做到这一点: var x = $('thing-that-was-clicked').closest('.ui-mobile-viewport'); alert(x.is('body')); alert(x.is('div')); 现在你有.ui-mobile-viewport元素作为jQuery对象,你可以运行你想要的任何测试,例如在上面的代码中检查body或div 。 Instead of doing the ... -
你需要包装li的内部内容并解开#this的内容 function cycle() { $("#ci").html(current_index); $('#this').contents().unwrap(); uli.eq(current_index).wrapInner(''); } var current_index = -1; var uli = $("#list li"); function cycle() { $(" ...
-
Selenium,JavaScript:从活动元素中提取元素CSS(Selenium, JavaScript: Extract Element CSS from Active Element)[2023-10-31]
driver.switchTo().activeElement(); 返回WebElement类型的对象。 将这个WebElement直接传递给你的抽象库会比从中反向设计一个CSS选择器更简单。 driver.switchTo().activeElement(); returns an object of the type WebElement. Passing this WebElement directly to your abstraction library would be simpler tha ... -
要缩小xpath查询传递查询的第二个参数: $articlesxpath = $xpath->query('//*[@id="content"]/article'); foreach($articlesxpath as $item){ // search in $item node $items = $xpath->query('article', $item); foreach($items as $ix) { var_dump($ix->nodeValue); ...
-
内部循环与Terraform(Inner looping with Terraform)[2022-02-16]
使用列表变量和其他复杂结构来“抽象”资源并不是惯用的,并且往往会导致难以阅读和维护的配置。 惯用的风格是使用子模块的多个实例来管理重复的构造。 例如,可以创建一个名为repository的子目录,其中包含repository.tf文件,如下所示: variable "name" { } variable "labels" { type = "list" } # can instead use github_team_repository here if appropriate resource "g ... -
更高级的方法,如果你认真学习C ++,你应该看看:不要使用索引和随机访问,使用高级STL函数。 考虑: #include
#include #include