qutebrowser/doc
Florian Bruhin ff5d4d3564 Avoid passing a parent to QProcess
With the upgrade to MarkupSafe 3.0, something funny happened when trying to pass
the GUIProcess object to jinja after launching a userscript:

    [...]
    File "[...]/qutebrowser/browser/qutescheme.py", line 291, in qute_process
        src = jinja.render('process.html', title=f'Process {pid}', proc=proc)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "[...]/qutebrowser/utils/jinja.py", line 123, in render
        return environment.get_template(template).render(**kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    [...]
    File "html/process.html", line 11, in block 'content'
    File "[...]/lib/python3.11/site-packages/markupsafe/__init__.py", line 42, in escape
        if hasattr(s, "__html__"):
           ^^^^^^^^^^^^^^^^^^^^^^
    RuntimeError: wrapped C/C++ object of type GUIProcess has been deleted

This can be reproduced with:

    qutebrowser --temp-basedir ':cmd-later 0 spawn -u -o /bin/echo test'

We pass the `GUIProcess` to the Jinja template as `proc`, which then formats it as
`{{ proc }}`` (to stringify it). For some reason, with the newest MarkupSafe/Jinja
versions, this now triggers the `if hasattr(s, "__html__")` check in MarkupSafe
(which has been around for a while). That then presumably causes PyQt to try and
access the underlying C++ object for `GUIProcess``, but that has already been
deleted.

But why is it deleted in the first place, if we keep track of even completed
processes data ever since we added `:process` in a3adba81c? It looks like the Qt
parent-child relationship is the culprit here: When we pass a parent to the
`GUIProcess`` from the userscript runner, it will get deleted as soon as said
runner is cleaned up (which happens after the userscript has finished).

We probably never noticed this before because we only accessed data from the
Python wrapper and not from the C++ side, but it still seems like a good idea
to avoid passing a parent for a long-lived object (with time-based cleanup) in
the first place.
2024-10-15 11:55:04 +02:00
..
extapi doc: Switch URLs to https 2021-01-26 15:19:01 +01:00
help Merge pull request #8268 from greenfoo/update_match_patterns_link 2024-07-27 11:13:16 +12:00
img Regenerate cheatsheet PNGs 2021-09-06 21:33:20 +02:00
backers.asciidoc Update backers.md 2023-11-10 16:03:12 +01:00
changelog.asciidoc Avoid passing a parent to QProcess 2024-10-15 11:55:04 +02:00
contributing.asciidoc Drop Python 3.8 from tox/CI 2024-10-13 18:24:44 +02:00
faq.asciidoc Fix some spelling errors 2024-05-09 10:58:04 -04:00
install.asciidoc Update docs for Python 3.8 drop 2024-10-13 18:24:44 +02:00
quickstart.asciidoc Move master branch references to main 2023-07-23 11:38:19 +02:00
qutebrowser.1.asciidoc reuse: Adjust most license headers 2023-07-23 12:11:07 +02:00
stacktrace.asciidoc doc: Fix link 2022-05-13 16:03:23 +02:00
userscripts.asciidoc feat: pass QUTE_TAB_INDEX to userscripts 2022-02-10 13:44:17 -07:00