GVKun编程网logo

在Python中进行冲洗时,如何防止BrokenPipeError?(怎么用python清洗数据)

18

针对在Python中进行冲洗时,如何防止BrokenPipeError?和怎么用python清洗数据这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展Flask应用收到“IOError:[Er

针对在Python中进行冲洗时,如何防止BrokenPipeError?怎么用python清洗数据这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展Flask应用收到“IOError: [Errno 32] Broken pipe”、PermissionError:[Errno 13]在python中、Python memory error的问题&BrokenPipeError的问题RunTime Error:CUDA的问题、python socket:[Errno 32] Broken pipe等相关知识,希望可以帮助到你。

本文目录一览:

在Python中进行冲洗时,如何防止BrokenPipeError?(怎么用python清洗数据)

在Python中进行冲洗时,如何防止BrokenPipeError?(怎么用python清洗数据)

问题:有没有办法使用flush=Trueprint()函数的方法BrokenPipeError

我有一个脚本pipe.py

for i in range(4000):    print(i)

我从Unix命令行这样称呼它:

python3 pipe.py | head -n3000

它返回:

012

这个脚本也是如此:

import sysfor i in range(4000):    print(i)    sys.stdout.flush()

但是,当我运行此脚本并将其通过管道传递给时head -n3000

for i in range(4000):    print(i, flush=True)

然后我得到这个错误:

    print(i, flush=True)BrokenPipeError: [Errno 32] Broken pipeException BrokenPipeError: BrokenPipeError(32, ''Broken pipe'') in <_io.TextIOWrapper name=''<stdout>'' mode=''w'' encoding=''UTF-8''> ignored

我也尝试了下面的解决方案,但仍然得到了BrokenPipeError

import sysfor i in range(4000):    try:        print(i, flush=True)    except BrokenPipeError:        sys.exit()

答案1

小编典典

BrokenPipeError是正常现象,因为读过程(头)会终止并关闭管道的末端,而写过程(python)仍会尝试进行写操作。

Is
一种异常情况,并且python脚本收到一个BrokenPipeError-更准确地说,Python解释器收到一个系统SIGPIPE信号,该信号捕获并引发该信号BrokenPipeError以允许脚本处理错误。

而且您可以有效地处理该错误,因为在上一个示例中,您仅看到一条消息,指出忽略了该异常-
好的,这不是真的,但似乎与Python中的这个开放问题有关:Python开发人员认为警告用户注意非常重要异常情况。

真正发生的是,即使您捕获到异常,Python解释器AFAIK始终会在stderr上发出信号。但是您只需要在退出前关闭stderr即可消除该消息。

我将您的脚本稍微更改为:

  • 像上一个示例一样捕获错误
  • 捕获IOError(在Windows64上为Python34)或BrokenPipeError(在FreeBSD 9.0上为Python 33)-并显示一条消息
  • 在stderr上显示自定义的 “完成” 消息(由于管道断开,stdout已关闭)
  • *退出以 *关闭 消息之前 关闭stderr

这是我使用的脚本:

import systry:    for i in range(4000):            print(i, flush=True)except (BrokenPipeError, IOError):    print (''BrokenPipeError caught'', file = sys.stderr)print (''Done'', file=sys.stderr)sys.stderr.close()

这是以下结果python3.3 pipe.py | head -10

0123456789BrokenPipeError caughtDone

如果您不想要多余的消息,请使用:

import systry:    for i in range(4000):            print(i, flush=True)except (BrokenPipeError, IOError):    passsys.stderr.close()

Flask应用收到“IOError: [Errno 32] Broken pipe”

Flask应用收到“IOError: [Errno 32] Broken pipe”

现在,我使用flask开发Web应用程序。

但是起初它运行良好,在操作了一段时间的网页后,我使用flask开发Web应用程序后端显示如下错误:

   File "/usr/lib64/python2.6/BaseHTTPServer.py", line 329, in handle    self.handle_one_request()  File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 251, in handle_one_request    return self.run_wsgi()  File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 193, in run_wsgi    execute(self.server.app)  File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 184, in execute    write(data)  File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 152, in write    self.send_header(key, value)  File "/usr/lib64/python2.6/BaseHTTPServer.py", line 390, in send_header    self.wfile.write("%s: %s\r\n" % (keyword, value))IOError: [Errno 32] Broken pipe

我的应用程序在端口5000上运行app.run(debug=True,port=5000)

我使用nginx作为Web服务器,并proxy_pass http://127.0.0.1:5000在nginx配置文件中进行设置。

现在我真的不知道哪里出了问题,我使用的session[''email''] = request.form[''email'']是其他文件email = session.get(''email'')

这种用法正确吗?如何设置会话有效期?

还是任何其他原因导致此错误?

然后我设置app.run(debug=False,port=5000),它显示新的错误

File "/usr/lib64/python2.6/SocketServer.py", line 671, in finish    self.wfile.flush()  File "/usr/lib64/python2.6/socket.py", line 303, in flush    self._sock.sendall(buffer(data, write_offset, buffer_size))socket.error: [Errno 32] Broken pipe

为什么呢?

答案1

小编典典

内置的werkzeug服务器无法处理远程终端,而该服务器仍在寻找其内容时关闭了连接。

代替 app.run(debug=True,port=5000)

尝试

from gevent.wsgi import WSGIServerhttp_server = WSGIServer(('''', 5000), app)http_server.serve_forever()

或者如果你使用的是nginx,与uwsgi一起使用

werkzeug我会争论这是一个问题

PermissionError:[Errno 13]在python中

PermissionError:[Errno 13]在python中

刚开始学习一些python时,我遇到了如下问题:

a_file = open('E:\Python Win7-64-AMD 3.3\Test',encoding='utf-8')

Traceback (most recent call last):
  File "<pyshell#9>",line 1,in <module>
    a_file = open('E:\Python Win7-64-AMD 3.3\Test',encoding='utf-8')
PermissionError: [Errno 13] Permission denied: 'E:\\Python Win7-64-AMD 3.3\\Test\

似乎是文件许可错误,如果任何人都可以发光一点,将不胜感激。

注意:不确定Python和Windows文件如何工作,但是我以Admin身份登录Windows,并且该文件夹具有admin权限。

我试图更改.exe属性以管理员身份运行。

Python memory error的问题&BrokenPipeError的问题RunTime Error:CUDA的问题

Python memory error的问题&BrokenPipeError的问题RunTime Error:CUDA的问题

https://blog.csdn.net/weixin_39750084/article/details/81501395

https://blog.csdn.net/zichen7055/article/details/83064301

epoch和batch_size

GPU Capacity:GPU容量

 

_pickle.picklingError:can''t pickle <class ''MemoryError''>:It''s not the same object as builtins.Memory

   return torch.stack(img, 0), torch.cat(label, 0), path, shapes

RuntimeError: [enforce fail at ..\c10\core\CPUAllocator.cpp:72] data. DefaultCPUAllocator:not enough memory: you tried to allocate 33226752 bytes. Buy new RAM!

:https://stackoverflow.com/questions/56272981/pytorch-runtimeerror-enforce-fail-at-cpuallocator-cpp56-posix-memaligndata

 

DeepNude:https://www.fujieace.com/jingyan/deepnude2-0.html

 

Pytorch RuntimeError: CUDNN_STATUS_INTERNAL_ERROR的解决办法:https://blog.csdn.net/eagelangel/article/details/82821718    https://www.wandouip.com/t5i241566/    https://www.cnblogs.com/aoru45/p/10811428.html  

 

deepnude只有女性版,没有男性版,这是对男性的歧视,那么如何开发男性版呢?

1. 加载原图

2.根据人体结构原理判断他大概的人体结构(2d+3d)

 

3. 除去衣服,换上男性人体皮肤

问题:身体颜色和人脸不一致,第二这个体型的人不应该这么壮吧?

python socket:[Errno 32] Broken pipe

python socket:[Errno 32] Broken pipe

这个错误发生在当client端close了当前与你的server端的socket连接,但是你的server端在忙着发送数据给一个已经断开连接的socket。

下面是stackoverflow给的解决方案:

Your server process has received a SIGPIPE writing to a socket. This usually happens when you write to a socket fully closed on the other (client) side. This might be happening when a client program doesn''t wait till all the data from the server is received and simply closes a socket (using close function). In a C program you would normally try setting to ignore SIGPIPE signal or setting a dummy signal handler for it. In this case a simple error will be returned when writing to a closed socket. In your case a python seems to throw an exception that can be handled as a premature disconnect of the client.
下面是python的实现:
import socket
def hack_fileobject_close():
    if getattr(socket._fileobject.close, ''__hacked__'', None):
        return
    old_close = socket._fileobject.close
    def new_close(self, *p, **kw):
        try:
            return old_close(self, *p, **kw)                                                                                                                                    
        except Exception, e:
            print("Ignore %s." % str(e))
    new_close.__hacked__ = True
    socket._fileobject.close = new_close
hack_fileobject_close()

今天关于在Python中进行冲洗时,如何防止BrokenPipeError?怎么用python清洗数据的分享就到这里,希望大家有所收获,若想了解更多关于Flask应用收到“IOError: [Errno 32] Broken pipe”、PermissionError:[Errno 13]在python中、Python memory error的问题&BrokenPipeError的问题RunTime Error:CUDA的问题、python socket:[Errno 32] Broken pipe等相关知识,可以在本站进行查询。

本文标签: