0

我在运行 python 程序时遇到了一个问题。错误提示粘贴在下面。我在我的代码中使用 matplotlib.pyplot 库来实现实时拓扑图。程序可以成功运行,但是每次拖动绘图窗口都会跳出错误。我不知道如何解决它。请给我一些建议,谢谢和问候!

错误说:

Rumtime Error!
Program:D:\academic software\Python\pythonw.exe

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

代码:

from socket import *
from time   import ctime
from binascii import *
from sys import *
from d_deal import *
from d_trans import *
import sys
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
from threading import *
import networkx as nx
import matplotlib.pyplot as plt
from frame import *



app = QtGui.QApplication([])   
plt.ion()

#define the global variables
link=[]
link_list=[]    #the list of the links
link_loss=[]    #the loss time of the relevant links 
link_flags=[]    #the flag of whether del the link

global g
g=nx.Graph()
plt.figure("topology",figsize=(6,6),facecolor='white')


def tp_dorule():
    global f,link_list

    link_flag=1
    link_flag_sd=1
    link_flag_so=1


    if f.sour==f.orig:
        for i in range(len(link_list)):
            if (f.sour,f.dest)==link_list[i] or (f.dest,f.sour)==link_list[i]:
                link_flag=0
        if link_flag==1:
            link_list.append((f.sour,f.dest))
            link_loss.append(0)
            link_flags.append(1)
    else:
        for i in range(len(link_list)):
            if (f.sour,f.dest)==link_list[i] or (f.dest,f.sour)==link_list[i]:
                link_flag_sd=0
        for j in range(len(link_list)):
            if (f.sour,f.orig)==link_list[j] or (f.orig,f.sour)==link_list[j]:
                link_flag_so=0

        if link_flag_sd==1:
            link_list.append((f.sour,f.dest))
            link_loss.append(0)
            link_flags.append(1)
        if link_flag_so==1:
            link_list.append((f.sour,f.orig))
            link_loss.append(0)
            link_flags.append(1)
    print link_list

    for i in range(len(link_list)):
        if (f.sour,f.dest)!=link_list[i] and (f.dest,f.sour)!=link_list[i] and (f.orig,f.dest)!=link_list[i] and (f.dest,f.orig)!=link_list[i]:
             link_loss[i]+=1
        else:
             link_loss[i]=0
    print link_loss

def tp_update():
    global g,link_list
    plt.clf()
    link=[]
    for i in range(len(link_loss)):
        if link_loss[i]>=2:
            link_flags[i]=0
    for i in range(len(link_flags)):
        if link_flags[i]!=0:
            link.append(link_list[i])
    print link
    g.add_edges_from(link)
    pos=nx.spectral_layout(g)
    nx.draw(g,pos,with_labels=True,node_size=500)
    plt.draw()



def update():
    tp_update()


####the timer interrupte
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(1000)

####the data dealing part
def data_deal():
    print '2'
    #set the udp transportation parameters
    HOST = '127.0.0.1' 
    PORT = 1031
    BUFSIZ = 2048
    ADDR = (HOST, PORT)

    #the pid debug text
    PID=os.getpid()
    file=open("PID.txt",'w')
    file.write(str(PID))
    file.close()

    #binding the udp address
    udpSerSock = socket(AF_INET, SOCK_DGRAM)  
    udpSerSock.bind(ADDR)
    #the main function
    while True:
        #receive the raw data
        raw_data,addr=udpSerSock.recvfrom(BUFSIZ)

        if not raw_data:
            continue
        ##dealing with the raw_data(not solute yet)
        data=hexlify(raw_data)
        print data
        global f
        f=data_dealing(data)
        data_trans(f)
        print '1'
        if f.ftype != 'else frame' and f.ftype != 'ack frame':   
            tp_dorule()


th2 = Thread(target=data_deal)
th2.start()

if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        sys.exit(app.instance().exec_())
4

0 回答 0