Perform any cleanup actions in the logging system (e.g. flushing buffers). Should be called at application exit.
(handlerList=_handlerList)
| 2245 | root.manager._clear_cache() |
| 2246 | |
| 2247 | def shutdown(handlerList=_handlerList): |
| 2248 | """ |
| 2249 | Perform any cleanup actions in the logging system (e.g. flushing |
| 2250 | buffers). |
| 2251 | |
| 2252 | Should be called at application exit. |
| 2253 | """ |
| 2254 | for wr in reversed(handlerList[:]): |
| 2255 | #errors might occur, for example, if files are locked |
| 2256 | #we just ignore them if raiseExceptions is not set |
| 2257 | try: |
| 2258 | h = wr() |
| 2259 | if h: |
| 2260 | try: |
| 2261 | h.acquire() |
| 2262 | # MemoryHandlers might not want to be flushed on close, |
| 2263 | # but circular imports prevent us scoping this to just |
| 2264 | # those handlers. hence the default to True. |
| 2265 | if getattr(h, 'flushOnClose', True): |
| 2266 | h.flush() |
| 2267 | h.close() |
| 2268 | except (OSError, ValueError): |
| 2269 | # Ignore errors which might be caused |
| 2270 | # because handlers have been closed but |
| 2271 | # references to them are still around at |
| 2272 | # application exit. |
| 2273 | pass |
| 2274 | finally: |
| 2275 | h.release() |
| 2276 | except: # ignore everything, as we're shutting down |
| 2277 | if raiseExceptions: |
| 2278 | raise |
| 2279 | #else, swallow |
| 2280 | |
| 2281 | #Let's try and shutdown automatically on application exit... |
| 2282 | import atexit |