Skip to content

Commit cf77a60

Browse files
committed
Add close_logs() hook to log.py to avoid ResourceWarnings about unclosed files
1 parent 5d6bb5b commit cf77a60

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

plugins/log.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import asyncio
2-
import os
32
import codecs
3+
import os
44
import time
55

66
import cloudbot
77
from cloudbot import hook
88
from cloudbot.event import EventType
9-
10-
119
# +---------+
1210
# | Formats |
1311
# +---------+
12+
from cloudbot.hook import Priority
1413
from cloudbot.util.formatting import strip_colors
1514

1615
base_formats = {
@@ -253,3 +252,11 @@ def flush_log():
253252
stream.flush()
254253
for name, stream in raw_cache.values():
255254
stream.flush()
255+
256+
257+
@hook.on_stop(priority=Priority.LOWEST)
258+
def close_logs():
259+
for name, stream in stream_cache.values():
260+
stream.close()
261+
for name, stream in raw_cache.values():
262+
stream.close()

0 commit comments

Comments
 (0)