python2.7出现IOError: [Errno 5] Input/output error

来源:互联网 发布:家用健身器材 知乎 编辑:程序博客网 时间:2024/05/22 06:07

以下内容经过各路大神指点,所以属于转载内容:


你会发现,出现这种报错的时候,一定是在print语句地方报这种错。

直接注释掉就行了,但是有很多print就很麻烦了。


还有就是部署web的时候,比如哈,模块A调用了模块B,A是我们运行的Flask,例如

我们使用python A.py &部署,随后,我们又修改了B,但是没有重新部署A,那么这个时候就很容易出现这种报错。

所以每次修改了B以后,A最好重新运行部署下。


后来发现:重新部署flask后,过一段时间还是会出现IO error


python app_modify.py &

改为:

python app8_modify.py > message.log &
或者

python app8_modify.py > /dev/null 2>&1 &

然后,不要直接关闭终端,而是输入exit来关闭终端

据说这么搞的原因是,我们离线部署完终端以后,print语句没地方输出,就error了,所以改为重定向。

终端中出现killed是正常的。


部署flask web框架时可能遇到的问题有:

终端如果出现“Killed”,这个可能是以前关掉的进程,尽管已经关掉了,但是可能会在终端按下回车键以后“回显”

如果终端出现“Exit 1”这个是不正常的,必须解决


另外的4种办法是:

1、用notepad打开所有工程,把所有print全部替换成#print

2、

from __future__ import print_functiondef myprint(msg):    passprint=myprintprint("hehehehehe")

此时print结果不会输出到终端

3、

import sysclass MC:    def write(*_):        passsys.stdout=MC()a=5print "a=",a

此时print结果也不会输出到终端

4、

test.py

import syssys_out = sys.stdoutsys.stdout = open('./test.txt', 'w+')print '...'from test2 import aa()sys.stdout.close()sys.stdout = sys_out

test2.py

def a():    print "sifjo"

test.py和test2.py两个文件放在同一路径下

就可以达到屏蔽test2.py中的输出函数的效果


所以总结下,总共是2种shell 对print的重定向方法+1种notepad暴力替换法+3种python中的处理方法


参考链接:

http://blog.sina.com.cn/s/blog_4aae007d010192qc.html
http://blog.csdn.net/vbaspdelphi/article/details/52347251


阅读全文
0 0
原创粉丝点击