
环境为 docker for win10,出异常的地方:
fn = self.logDir + "/%d-%s-%s.log" % (self.no, level, cate) file_object = open(fn, 'a') file_object.write(logLine) file_object.close() 异常为:
Traceback (most recent call last): File "/app/src/master.py", line 160, in <module> File "/app/src/master.py", line 155, in run File "/app/src/utils.py", line 133, in log IOError: [Errno 5] Input/output error: '/app/var/log/0-warning-.log' dockerfile 为:
FROM centos:6 RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm && \ yum -y install https://centos6.iuscommunity.org/ius-release.rpm && \ yum -y install htop \ iftop \ git2u \ vixie-cron \ openssh-server \ strace \ python27 \ python27-pip && \ yum clean all RUN ( echo "root";sleep 1;echo "root" ) | passwd RUN git config --global credential.helper store ENV IMAGE_VER 0.3 RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo 'Asia/Shanghai' > /etc/timezone #不用 requirements.txt 而是分开安装在 docker 更快 #2.10.6 RUN pip2.7 install redis -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com #2.18.4 RUN pip2.7 install requests -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com #4.6.0 RUN pip2.7 install BS4 -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com #0.1.7 RUN pip2.7 install pytesseract -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com #3.5.0 RUN pip2.7 install ConfigParser -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com #3.8.0 RUN pip2.7 install selenium -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com CMD service crond start && service sshd start && /bin/bash 1 gouchaoer OP 实在搜不到解决方案,不知道啥原因导致的 |
2 gouchaoer OP 不止那个"/app/var/log/0-warning-.log"文件不能写,连别的文件也不能写: ``` Exception IOError: (5, 'Input/output erro', '/app/var/log/0-info-.log') in <bound method Master.__del__ of <__main__.Master object at 0x7f6f7aa9b8d0>> ignored ``` 我有点怀疑是因为我把 win 下的源码映射到 docker 容器的 /app 路径下,docker 容器是这么做的: ``` docker create -it --name test -v C:/Users/path/to/test:/app -p 23333:22 --cap-add SYS_PTRACE test:0.1 ``` |
3 gouchaoer OP 可是事后在 docker 容器里用 vim 也可以打开编辑那些 log 文件啊,比较迷 |
4 gouchaoer OP 也没有别的程序以写或者读打开那些 log 文件 |
5 ipwx 2018 年 1 月 24 日 看看文件句柄数量是不是超过了当前进程的限制数量。 https://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/ - - - - 每写一行打开一次文件不是好的 practice。请用 logging 模块。 |
6 MarcoQin 2018 年 1 月 24 日 请用 logging 模块 +1 |
7 Shazoo 2018 年 1 月 24 日 IOError: [Errno 5] Input/output error: '/app/var/log/0-warning-.log' 估计是 cate 参数为空导致的?感觉不是大问题。 |
8 yeyuexia 2018 年 1 月 24 日 lz 是不是在程序里开了多线程 /多进程啊 总觉得有点像是写冲突的样子……所以还是老老实实用 logging 吧…… |
9 gouchaoer OP 这和 logging 模块无关啊,我只是觉得它太弱了我自己定制了一个,然后打开文件又写了点东西而已,那是个合法的文件名 @ipwx lsof -n | grep 5950 -c 查出句柄一直是 59,没有泄漏啥的 |
10 gouchaoer OP 总之先这样,多谢各位了: ``` #t/425463 try: fn = self.logDir + "/%d-%s-%s.log" % (self.no, level, cate) file_object = open(fn, 'a') file_object.write(logLine) file_object.close() fn = self.logDir + "/%d.log" % (self.no) file_object = open(fn, 'a') file_object.write(logLine) file_object.close() except Exception, e: sys.stdout.write(e.message()) ``` |
11 lolizeppelin 2018 年 1 月 24 日 via Android 出错的时候 pwd 打出来 文件绝对路径打 出来 os path exit 上层目录看看 win 里切换过盘符没 切换了盘符没换回来出错正常 |