我正在从python ad开发C扩展我获得了一些段错误(在开发过程中不可避免......).
我正在寻找一种方法来显示段错误发生在哪一行代码(一个想法就像跟踪每一行代码),我该怎么做?
我试图让Theano在Raspberry Pi 3(B)上与Keras一起运行但没有成功.我尝试使用Ubuntu MATE和Raspbian作为操作系统,但没有成功.要安装Theano和Keras,我采取了以下步骤:
pip和apt-get上述步骤没有任何问题.在下一步中,我构建了一个小测试脚本(test.py),它通过加载已经构建的模型
from keras.models import load_model
model = load_model('model.hdf5')
Run Code Online (Sandbox Code Playgroud)
加载模型时,我收到以下错误
Segmentation fault (core dumped)
Run Code Online (Sandbox Code Playgroud)
然后我尝试进一步研究这个问题,关于SO的回答(导致Python分段错误的原因是什么?):
gdb python
> run test.py
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我得到:
Program received SIGSEV, Segmentation fault.
0x76fd9822 in ?? () from /lib/ld-linux-armhf.so.3
Run Code Online (Sandbox Code Playgroud)
在下一步中,我在gdb shell中运行:
> backtrace
Run Code Online (Sandbox Code Playgroud)
得到了
#0 0x76fd9822 in ?? () from /lib/ld-linux-armhf.so.3
#1 0x76fd983a in ?? () from /lib/ld-linux-armhf.so.3
Run Code Online (Sandbox Code Playgroud)
这是我不知道的地方,我想问一下,如果有人能指出我如何解决这个问题并让keras + theano在Raspberry Pi上运行.
(我也尝试过TensorFlow作为替代方案,但是遇到同样的问题)
非常感谢.
编辑
我做了一些调查.如果我用TensorFlow运行Keras,问题似乎会有所改变.我再次运行gdb,但错误现在发生在numpy中,尤其是在libopenblas.so.0中
Program received signal SIGSEV, Segmentation …Run Code Online (Sandbox Code Playgroud) 我正在将csh脚本转换为python脚本.该脚本调用内存密集型可执行文件,需要非常大的堆栈,因此csh脚本将stacksize设置为unlimited:
limit stacksize unlimited
Run Code Online (Sandbox Code Playgroud)
当我尝试在python中重现这个脚本时,我以一种非常天真的方式执行它们os.system,例如:
os.system('some_executable')
Run Code Online (Sandbox Code Playgroud)
但我不知道如何通过无限制的堆栈大小来告诉操作系统运行这些可执行文件.有没有办法为python脚本中的调用指定stacksize?是否有一些我应该使用的低级系统调用?是否有一个控制它的模块(类似于shutil)?
这会产生一个Segmentation Fault: 11,我不知道为什么.
在我进入之前,这是代码:
import numpy.random as nprnd
import heapq
import sys
sys.setrecursionlimit(10**6)
def rlist(size, limit_low, limit_high):
for _ in xrange(size):
yield nprnd.randint(limit_low, limit_high)
def iterator_mergesort(iterator, size):
return heapq.merge(
iterator_mergesort(
(iterator.__next__ for _ in xrange(size/2)), size/2),
iterator_mergesort(
iterator, size - (size/2))
)
def test():
size = 10**3
randomiterator = rlist(size, 0, size)
sortediterator = iterator_mergesort(randomiterator, size)
assert sortediterator == sorted(randomiterator)
if __name__ == '__main__':
test()
Run Code Online (Sandbox Code Playgroud)
基本上,它只是一个mergesort,它适用于迭代器和生成器表达式,而不是在列表上工作,以便在任何时候最小化内存占用.它没什么特别的,并使用heapq.merge()内置方法来合并迭代器,所以当一切都中断时我很惊讶.
快速运行代码Segmentation Fault: 11并给出一个错误窗口告诉我python崩溃了.我不知道在哪里看或如何调试这个,所以任何帮助将不胜感激.
当我在函数内部调用 BeautifulSoup() 时,我的网络抓取工具会抛出NameError: name 'BeautifulSoup' is not defined异常,但当我在函数外部调用它并将 Soup 作为参数传递时,它会正常工作。
这是工作代码:
from teams.models import *
from bs4 import BeautifulSoup
from django.conf import settings
import requests, os, string
soup = BeautifulSoup(open(os.path.join(settings.BASE_DIR, 'revolver.html')), 'html.parser')
def scrapeTeamPage(soup):
teamInfo = soup.find('div', 'profile_info')
...
print(scrapeTeamPage(soup))
Run Code Online (Sandbox Code Playgroud)
但是当我将 BeautifulSoup 调用移动到我的函数中时,我收到错误。
from teams.models import *
from bs4 import BeautifulSoup
from django.conf import settings
import requests, os, string
def scrapeTeamPage(url):
soup = BeautifulSoup(open(os.path.join(settings.BASE_DIR, url)), 'html.parser')
teamInfo = soup.find('div', 'profile_info')
Run Code Online (Sandbox Code Playgroud) 我正在使用 PySide2 和 scikit-learn 开发一个应用程序。如果我使用单线程,应用程序可以正常工作,但如果我将 sckikit-learn 计算移至工作 QThread(以在处理过程中保持 UI 响应),我会在 Mac OS Catalina 上遇到随机分段错误。同一个程序似乎在 Windows 上运行良好(在 Mac 上,我每次运行该程序时都会遇到分段错误;我在 Windows 上运行该程序至少二十次,但从未崩溃)。我试图遵循此答案中的建议,但我无法在 Catalina 上gdb正常lldb工作。
这就是我得到的lldb:
% lldb python
(lldb) target create "python"
Current executable set to 'python' (x86_64).
(lldb) run test.py
error: process exited with status -1 (attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries when the attached failed. The subsystem that denied the …Run Code Online (Sandbox Code Playgroud)