]> git.neil.brown.name Git - edlib.git/commitdiff
w3m: write html to tempfile, not to a pipe.
authorNeilBrown <neil@brown.name>
Tue, 17 Oct 2023 05:43:47 +0000 (16:43 +1100)
committerNeilBrown <neil@brown.name>
Tue, 17 Oct 2023 05:43:47 +0000 (16:43 +1100)
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 <neil@brown.name>
DOC/TODO.md
python/lib-html-w3m.py

index a4f79a5f29491c181fe10d077c3acc4d7e4a0b38..a1ab4b73c5de9353c93e53dfe2bc7e9e7f9344dd 100644 (file)
@@ -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
index 6da8ed2228364b3cdad6a03259e5efe1830697e5..4e86db523dc4ce98d7546b24ebe81049b725628b 100644 (file)
@@ -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)