python logging 异常是怎么回事 谁能告诉我该怎么解决呢
我在Ctrl + C 终止多线程的时候 有的时候会报以下异常 我觉得应该是logging报出的 麻烦各位告诉我解决方法 多谢
logging.conf配置文件:
#logging.conf
[loggers]
keys=root,spider
[handlers]
keys=consoleHandler,rotateFileHandler
[formatters]
keys=simpleFormatter
[formatter_simpleFormatter]
format=[%(asctime)s](%(levelname)s)%(name)s : %(message)s
[logger_root]
level=DEBUG
handlers=consoleHandler,rotateFileHandler
[logger_spider]
level=DEBUG
handlers=consoleHandler,rotateFileHandler
qualname=spider
propagate=0
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)
[handler_rotateFileHandler]
class=handlers.RotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=('../log/spider.log', 'a', 1024 * 1024 * 600, 50)
报的异常:
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/local/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/local/lib/python2.6/logging/__init__.py", line 1509, in shutdown
[2000-01-11 21:58:49,718](INFO)spider : [taskrunner]:thread exit:task_thd_1
h.close()
File "/usr/local/lib/python2.6/logging/__init__.py", line 828, in close
self.stream.close()
IOError: close() called during concurrent operation on the same file object.
Error in sys.exitfunc:
Traceback (most recent call last):
File "/usr/local/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/local/lib/python2.6/logging/__init__.py", line 1509, in shutdown
h.close()
File "/usr/local/lib/python2.6/logging/__init__.py", line 828, in close
self.stream.close()
IOError: close() called during concurrent operation on the same file object.
[解决办法]
对同一个文件对象进行了并发的close操作。在close处判断一下并加锁就行了。