字典初始化python的seg断层
因此,我正在研究一个处理大量车辆和这些车辆之间的变速器的项目。我有一个工作代码,可以很好地适用于少量车辆,但是当我开始使用大量〜500辆车时,该程序将使故障大约一半时间。我已经使用faulthandler()回溯了SEG故障,并且字典初始化是程序当前故障的位置。这是字典初始化的代码:
for j in range(self.num_vehicles): # for each vehicle
if self.timeIndex == 0:
self.vehicles[j].pseudo_random_number(0)
self.seconds = []
for j in range(500):
mso = self.vehicles[j].full_mso_range()
vehicle_transmissions = []
for k in range(500):
vehicle_transmissions.append(0)
# Iterate through all of the other vehicles besides vehicle j
for k in range(j+1, j+500):
distance = float(np.ceil(np.sqrt(
(self.vehicles[j].position[0] - self.vehicles[k % self.num_vehicles].position[0]) ** 2.0 +
(self.vehicles[j].position[1] - self.vehicles[k % self.num_vehicles].position[1]) ** 2.0 +
(self.vehicles[j].position[2] - self.vehicles[k % self.num_vehicles].position[2]) ** 2.0)))
transmission = {"receiverID": int(k%500),
"distance": 0,
"receivedpower": 0,
"successfuldecode": 0}
vehicle_transmissions[transmission["receiverID"]] = transmission # store transmission
self.vehicles[j].transmissions = vehicle_transmissions.copy() # save transmission to vehicle
self.vehicles[j].frame += 1 # increase frame
self.seconds.append(mso) # record MSO in a list that helps with collisions
分配传输的情况下发生SEG故障。我试图简化分配,因此请尝试隔离故障,但到目前为止我还没有运气。任何建议将不胜感激。
另外,该代码是通过C ++代码调用的,而GDB仅告诉我该功能中的SEG故障正在发生。
So I am working on a project that deals with a large number of vehicles and transmissions between those vehicles. I have a working code that works well for small numbers of vehicles, but when I start using large numbers ~500 vehicles then the program will seg fault about half the time. I have backtraced the seg fault using faulthandler() and the dictionary initialization is where the program currently faults. Here is the code for the dictionary initialization:
for j in range(self.num_vehicles): # for each vehicle
if self.timeIndex == 0:
self.vehicles[j].pseudo_random_number(0)
self.seconds = []
for j in range(500):
mso = self.vehicles[j].full_mso_range()
vehicle_transmissions = []
for k in range(500):
vehicle_transmissions.append(0)
# Iterate through all of the other vehicles besides vehicle j
for k in range(j+1, j+500):
distance = float(np.ceil(np.sqrt(
(self.vehicles[j].position[0] - self.vehicles[k % self.num_vehicles].position[0]) ** 2.0 +
(self.vehicles[j].position[1] - self.vehicles[k % self.num_vehicles].position[1]) ** 2.0 +
(self.vehicles[j].position[2] - self.vehicles[k % self.num_vehicles].position[2]) ** 2.0)))
transmission = {"receiverID": int(k%500),
"distance": 0,
"receivedpower": 0,
"successfuldecode": 0}
vehicle_transmissions[transmission["receiverID"]] = transmission # store transmission
self.vehicles[j].transmissions = vehicle_transmissions.copy() # save transmission to vehicle
self.vehicles[j].frame += 1 # increase frame
self.seconds.append(mso) # record MSO in a list that helps with collisions
The Seg Fault occurs where the transmission is allocated. I have tried to simplify the allocation so try and isolate the fault but I have had no luck so far. Any advice would be appreciated.
Also this code is called through a c++ code and gdb only tells me that the seg fault is happening in this function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题最终是Python到C ++接口的错误。它只有在有大量呼叫时才发生,它似乎在内存中失去了位置,并且访问该点再次遇到错误时。我最终只是在解决问题的C ++中编写完整的代码。如果其他人读到这一点,则更容易从C ++读取,该C ++将调用Python而不是调用C ++。
The problem ended up being a error in the python to C++ interface. It only happens when there is a large number of calls, it seems to lose its place in memory and when it accesses that point again hits an error. I ended up just writing the complete code in C++ which solves the problem. If anyone else reads this its easier to go from C++ which calls Python rather than Python calling C++.