From 40614c106fc854bb04a4e380f98b92b94ea771ea Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Sun, 15 Aug 2021 00:02:42 +0000 Subject: [PATCH] Work around OSX bug with too many open handles for afp background animations. --- bemani/utils/afputils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bemani/utils/afputils.py b/bemani/utils/afputils.py index 42754e0..4a036a6 100644 --- a/bemani/utils/afputils.py +++ b/bemani/utils/afputils.py @@ -620,8 +620,11 @@ def render_path( background: List[Image.Image] = [] if os.path.isfile(background_image): - # This is a direct reference. - bgimg = Image.open(background_image) + # This is a direct reference, open it. + with open(background_image, "rb") as bfp: + # Work around the fact that PIL does not read the image until first use, + # meaning a long background image sequence can blow past max open files. + bgimg = Image.open(io.BytesIO(bfp.read())) frames = getattr(bgimg, "n_frames", 1) if frames == 1: @@ -662,7 +665,10 @@ def render_path( # Now that we have the list, lets load the images! for filename in filenames: - bgimg = Image.open(filename) + with open(filename, "rb") as bfp: + # Work around the fact that PIL does not read the image until first use, + # meaning a long background image sequence can blow past max open files. + bgimg = Image.open(io.BytesIO(bfp.read())) frames = getattr(bgimg, "n_frames", 1) if frames == 1: