Removing handlers from python's logging loggers

后端 未结 4 1905
礼貌的吻别
礼貌的吻别 2020-12-13 23:03

I am playing with Python\'s logging system. I have noticed a strange behavior while removing handlers from a Logger object in a loop. Namely, my for loop removes all but one

4条回答
  •  旧时难觅i
    2020-12-13 23:37

    This isn't logger-specific behaviour. Never mutate (insert/remove elements) the list you're currently iterating on. If you need, make a copy. In this case testLogger.handlers = [] should do the trick.

提交回复
热议问题