jieba
jieba copied to clipboard
Fixing unclosed file warnings
Hello,
There are some open()
calls which are not closed after the use. Leaving file handles open leaks resources and makes Python raise warning such as the one bellow:
/Users/coder/project/extract.py:72: ResourceWarning: unclosed file <_io.BufferedReader name='/Users/coder/project/resources/keywords/zh/userdict.txt'>
jieba.load_userdict(str(p))
ResourceWarning: Enable tracemalloc to get the object allocation traceback
This change closes all open file handles.
This change should also solve issue reported here: https://github.com/fxsjy/jieba/issues/546 .
Thank you!