Errno 32: Broken pipe

1.3k views Asked by At

Below is the code for which I am getting Broken Pipe error. I am not getting this error for small data sets. This arises only when the data set is large. I am not able to handle it through exceptions also.

## 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

Below is the error I am getting

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

There are 1 answers

4
Anand S Kumar On BEST ANSWER

Seems like you are using Spyder IDE.

This seems like a known issue in Spyder 2.1.10 , according to Issue 1474 (Issue 1106) .

The fix seems to be available in Spyder 2.2.