【问题标题】:Errno 32: Broken pipeErrno 32:断管
【发布时间】:2015-06-24 19:11:53
【问题描述】:

下面是我收到 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

【问题讨论】:

    标签: python linux broken-pipe


    【解决方案1】:

    看来您正在使用 Spyder IDE。

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

    该修复似乎在 Spyder 2.2 中可用。

    【讨论】:

    • 谢谢@Ananad。我正在研究 Debian。当我尝试升级应用程序时,Spyder 2.1.10 是它显示的最新版本。
    • 尝试从这里获取一个 spyder 包 - neuro.debian.net/pkgs/spyder.html
    • 我现在可以获取 spyder 2.3.5.2。我希望这能解决问题。但我现在得到一个新的 NameError 。 Traceback(最近一次调用最后一次):文件“”,第 1 行,在 NameError: name 'runfile' is not defined
    • 是的。这就是完整的 Traceback。后来我通过python控制台运行它。工作正常。
    猜你喜欢
    • 2020-07-20
    • 2018-11-01
    • 2020-07-06
    • 2012-08-05
    • 2021-01-04
    • 2017-04-22
    • 2014-04-28
    • 1970-01-01
    • 2013-04-16
    相关资源
    最近更新 更多