jieba icon indicating copy to clipboard operation
jieba copied to clipboard

Fixing unclosed file warnings

Open alex-wearisma opened this issue 3 years ago • 0 comments

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!

alex-wearisma avatar Jul 25 '21 14:07 alex-wearisma