From fc721096a6f7af9a753f76ad75d8905369059135 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 17 Oct 2023 16:43:47 +1100 Subject: [PATCH] w3m: write html to tempfile, not to a pipe. If the HTML is large and w3m passes it straight through, we can block writing to the pipe. So write to a temp file first instead. Signed-off-by: NeilBrown --- DOC/TODO.md | 4 ++-- python/lib-html-w3m.py | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/DOC/TODO.md b/DOC/TODO.md index a4f79a5f..a1ab4b73 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -9,9 +9,9 @@ the file. ### Triage -- [ ] w3m hangs for CAAmjac0r78WpiYW9FsJK=+E8-FG4MoxD2zkUJS_oCRyNW+=rug@mail.gmail.com +- [X] w3m hangs for CAAmjac0r78WpiYW9FsJK=+E8-FG4MoxD2zkUJS_oCRyNW+=rug@mail.gmail.com It is writing to stdout which is reading very slowly. -- [ ] in filename competion, TAB might add a '/' to a partial name and +- [ ] in filename completion, TAB might add a '/' to a partial name and then get confused. - [X] when search succeeds on final line then trying again loops back to there, redraw is strange diff --git a/python/lib-html-w3m.py b/python/lib-html-w3m.py index 6da8ed22..4e86db52 100644 --- a/python/lib-html-w3m.py +++ b/python/lib-html-w3m.py @@ -14,6 +14,7 @@ import edlib import os, fcntl import subprocess +import tempfile def get_attr(tagl, tag, attr): # Find attr="stuff" in tag, but search for tag in tagl @@ -43,6 +44,10 @@ class w3m_pane(edlib.Pane): def handle_visible(self, key, focus, **a): "handle:convert-now" + tf = tempfile.TemporaryFile() + tf.write(self.content.encode()) + tf.seek(0) + p = subprocess.Popen(["/usr/bin/w3m", "-halfdump", "-o", "ext_halfdump=1", "-I", "UTF-8", "-O", "UTF-8", "-o", "display_image=off", @@ -52,12 +57,8 @@ class w3m_pane(edlib.Pane): close_fds = True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - stdin=subprocess.PIPE) + stdin=tf.fileno()) self.pipe = p - # FIXME this could block if pipe fills - os.write(p.stdin.fileno(), self.content.encode()) - p.stdin.close() - p.stdin = None fd = p.stdout.fileno() fcntl.fcntl(fd, fcntl.F_SETFL, fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK) -- 2.43.0