Fix ResourceWarning on unclosed icon file
This commit is contained in:
1 parent
ab9b155250
commit
9dc7a1d65f
3 files changed
+25
-21
No files matched your search
@@ -6,6 +6,7 @@ import string
|
||||
import asyncio
|
||||
import logging
|
||||
import traceback
|
||||
import tkinter as tk
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from functools import wraps
|
||||
@@ -17,6 +18,8 @@ from typing import (
|
||||
)
|
||||
|
||||
import yarl
|
||||
from PIL.ImageTk import PhotoImage
|
||||
from PIL import Image as Image_module
|
||||
|
||||
from constants import JsonType
|
||||
from exceptions import ExitRequest, ReloadRequest
|
||||
@@ -38,6 +41,13 @@ _JSON_T = TypeVar("_JSON_T", bound=Mapping[Any, Any])
|
||||
logger = logging.getLogger("TwitchDrops")
|
||||
|
||||
|
||||
def get_photo_image(master: tk.Misc, path: Path | str) -> PhotoImage:
|
||||
image = Image_module.open(path)
|
||||
photo = PhotoImage(master=master, image=image)
|
||||
image.close()
|
||||
return photo
|
||||
|
||||
|
||||
async def first_to_complete(coros: abc.Iterable[abc.Coroutine[Any, Any, _T]]) -> _T:
|
||||
# In Python 3.11, we need to explicitly wrap awaitables
|
||||
tasks = [asyncio.ensure_future(coro) for coro in coros]
|
||||
|
||||
Reference in new issue
Block a user