python - 无法从 gui 中的堆栈溢出中恢复
问题描述
我的代码运行了两分钟,然后给出了这个错误:
致命的 Python 错误:无法从堆栈溢出中恢复。当前线程 0x000001d4(最近的调用优先):
我正在使用 wxpython 并从我有无限数据的串行端口('COM9')获取数据。我使用wx.Timer
和list.append
。
为了不给堆栈溢出,我使用计时器删除了我的列表。在 2 分钟内我运行代码,一切都很好。但是即使我删除了列表并且我的列表长度只有 76,我的应用程序也会冻结并且不会继续。
也许我应该在 wx 中尝试wxCallAfter
和wxCallLater
或“线程和处理”,但不建议在 wx 中使用线程和处理)。
或者也许我以后不应该使用append.list
和删除它?如果问题是因为我的数据结构,我应该改用什么?
# -*- coding: utf-8 -*-
import wx
from gui import *
#import _pickle as pickle
import pickle
import serial
import matplotlib.pyplot as plt
import matplotlib.pyplot
import numpy as np
import matplotlib.animation as animation
from test.test_zipfile import StoredBadCrcTests
import time
print("0")
ser = serial.Serial('COM9',9600)
fig, ax= plt.subplots()
x=[]
y=[]
x1=[]
x2=[]
y1=[]
y2=[]
i=0
storage=[]
class selam ( MyFrame1 ):
print("1")
def __init__( self, parent ):
MyFrame1.__init__ ( self, parent)
print("here")
self.m_timer1 = wx.Timer()
self.m_timer1.SetOwner( self, 1 )
self.m_timer2 = wx.Timer()
self.m_timer2.SetOwner( self, 2 )
self.m_timer3 = wx.Timer()
self.m_timer3.SetOwner( self, 3 )
self.m_timer4 = wx.Timer()
self.m_timer4.SetOwner( self, 4 )
# Connect Events
self.Bind( wx.EVT_TIMER, self.timer1, id=1 )
self.Bind( wx.EVT_TIMER, self.timer2, id=2 )
self.Bind( wx.EVT_TIMER, self.timer3, id=3 )
self.Bind( wx.EVT_TIMER, self.timer4, id=4 )
def __del__( self ):
pass
def tgl1( self, event ):
if self.m_timer1.IsRunning():
self.m_timer1.Stop()
print("timer 1 stopped")
else:
print("tgl_timer 1 starting...")
self.m_timer1.Start( 1000 )
def tgl2( self, event ):
if self.m_timer2.IsRunning():
self.m_timer2.Stop()
plt.close()
print("timer 2 stopped")
else:
print("tgl_timer 2 starting...")
self.m_timer2.Start( 501 )
def tgl3( self, event ):
if self.m_timer3.IsRunning():
self.m_timer3.Stop()
plt.close()
print("timer 3 stopped")
else:
print("tgl_timer 3 starting...")
self.m_timer3.Start( 2000 )
def tgl4( self, event ):
if self.m_timer4.IsRunning():
self.m_timer4.Stop()
plt.close()
print("timer 4 stopped")
else:
print("tgl_timer 4 starting...")
self.m_timer4.Start( 1000 )
########## data and all code has to written inside of timer(1,2,3,4..)
def timer1( self, event ):
print("1")
for line in ser:
storage.append(line)
#===================================================================
# f1 = open('C:\\Users\\GCS-User\\Desktop\\obj_pi','wb')
# pickle.dump(line,f1)
#
# f2=open('C:\\Users\\GCS-User\\Desktop\\obj_pi','rb')
# print(pickle.load(f2))
#===================================================================
def timer2( self, event ):
print("22")
del storage[:]
def timer3( self, event ):
print("333")
def timer4( self, event ):
print("4444")
def sV_sat(i):
#print("a")
for line in storage:
print("b")
print("storage_len:",len(storage))
data = line.split(b",")
#print("data_0:",data[0])
if data[0] == b'$GNGGA':
print("c")
altitude=data[9]
timm=data[1]
tim=float(timm)
tim=tim+30000
hour = tim//10000
minute = (tim//100)%100
second = tim%100
zaman = hour*3600 + minute*60 + second
altitude=float(altitude)
x.append(zaman)
y.append(altitude)
ax.plot(x,y)
ani8 = animation.FuncAnimation(fig,sV_sat)
plt.show()
if __name__ == "__main__":
app = wx.App(0)
frame = selam(None)
frame.Show()
app.MainLoop()
解决方案
推荐阅读
- reactjs - 在 React JSX 中单击按钮时滚动到组件
- c# - 如何替换通用列表中每个实例的交换 2 个属性?
- cassandra - Cassandra:压缩时的内存消耗
- c++ - 为什么 boost::cubic_b_spline 似乎拉伸了我的数据?
- c++ - 用函数返回的另一个向量初始化一个向量
- gatsby - 如何删除 src/pages/index.js 文件并在 gatsby 中使用 gatsby-node.js 动态创建它?
- html - 如何 用圆圈替换标签
- r - 如何在 R 中创建测验分数变量
- c++ - 无向图中的最大成本路径,使得没有两次访问边
- spring - 将 OpenJPA 升级到 Hibernate 时的性能问题