Errno 32:管子破了

时间:2015-06-24 19:11:54

标签: python linux broken-pipe

下面是我收到Broken Pipe错误的代码。我没有收到小数据集的这个错误。仅当数据集很大时才会出现这种情况。我也无法通过例外处理它。

## reading the data from CSV file
import csv
csv_file='Two_Patterns_TRAIN.csv'
data=[]
with open (csv_file,'rb') as csv_file:
    csvreader=csv.reader(csv_file, delimiter=';',quotechar='|')
    ## fetch the rows one by one
    for row in csvreader:
        ## split the rows in columns
        columns=row[0].split(',')
        myrow=[]        
        for col in range(len(columns)):
            ## fetch the columns one by one and append it to the according row
            myrow.append(float(columns[col]))
        data.append(myrow)


def dtw(seqA, seqB, d = lambda x,y: abs(x-y)):
    # create the cost matrix
    numRows, numCols = len(seqA), len(seqB)
    cost = [[0 for _ in range(numCols)] for _ in range(numRows)]

    # initialize the first row and column
    cost[0][0] = d(seqA[0], seqB[0])
    for i in xrange(1, numRows):
        cost[i][0] = cost[i-1][0] + d(seqA[i], seqB[0])

    for j in xrange(1, numCols):
        cost[0][j] = cost[0][j-1] + d(seqA[0], seqB[j])

    # fill in the rest of the matrix
    for i in xrange(1, numRows):
        for j in xrange(1, numCols):
            choices = cost[i-1][j], cost[i][j-1], cost[i-1][j-1]
            cost[i][j] = min(choices) + d(seqA[i], seqB[j])

    return cost[-1][-1]

def knn(mat,k):
    ## fetch number of rows and columns of the matrix
    nrow=len(mat)
    if nrow<k:
        print "K can not be larger than n-1"
        return
    neigh=[[0]*k for i in range(nrow)]
    for i in range(nrow):
        dist=[[0]*2 for count in range(nrow)]
        for j in range(nrow):
            dist[j][0]=j+1
            dist[j][1]=dtw(mat[i],mat[j])
        dist = sorted(dist, key=lambda a_entry: a_entry[1]) 
        neigh[i]=[row[0] for row in dist][1:k+1]
#        print neigh
    return neigh

a=data[:500]
b=data[501:]
try:
    c=knn(a,5)
except IOError, e:
    print e

以下是我得到的错误

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py", line 588, in run
    already_pickled=True)
  File "/usr/lib/python2.7/dist-packages/spyderlib/utils/bsdsocket.py", line 24, in write_packet
    sock.send(struct.pack("l", len(sent_data)) + sent_data)
error: [Errno 32] Broken pipe

1 个答案:

答案 0 :(得分:1)

好像你正在使用Spyder IDE。

根据Issue 1474Issue 1106),这似乎是Spyder 2.1.10中的一个已知问题。

修补程序似乎可以在Spyder 2.2中使用。