WayneD / script.tv.show.next.aired

Updated Next Aired addon for XBMC.
http://forum.xbmc.org/showthread.php?tid=186090
GNU General Public License v2.0
14 stars 20 forks source link

Bug: Too many open files #6

Closed ac3d912 closed 8 years ago

ac3d912 commented 8 years ago

Every now and then this script throws this error. Looks like you are using "file" to open a file and do a read. The problem is, that creates a file handle, but you never close it (this similar technique is used a couple of times in the script). I believe I've fixed the problem(s) (using a "with open" block), if you like I'll just send ya a pull request.

Log: 12:55:52 T:140662057989888 ERROR: Traceback (most recent call last): 12:55:52 T:140662057989888 ERROR: File "/home/user/.kodi/addons/script.tv.show.next.aired/default.py", line 1210, in load_file 12:55:52 T:140662057989888 ERROR: IOError: [Errno 24] Too many open files: u'/home/user/.kodi/userdata/addon_data/script.tv.show.next.aired/country.db'

Code:

    @staticmethod
    def load_file(file_path):
        try:
            return eval(file(file_path, "r").read())
WayneD commented 8 years ago

Thanks for pointing that out. I've changed the load/save code both to use "with" and also to switch from file() to open(). I also changed various urllib and ZipFile opens to use similar "with" idioms (and a closing helper from contextlib). See the 58bcd44c54e7a91b159775eff3861c01e953e8e9 commit.