Open dolfandringa opened 2 years ago
Ok, I did a little more digging.
Adding a return
at the start of update_indicator
and update_indicator_icon
didn't change anything. So its probably not the appindicator code. I also manually executed the gsettings commands from the update script, and those didn't trigger it either. BUt I do see this code:
def set_wp_throttled(self, filename, refresh_level=RefreshLevel.ALL):
if not filename:
logger.warning(lambda: "set_wp_throttled: No wallpaper to set")
return
self.thumbs_manager.mark_active(file=filename, position=self.position)
def _do_set_wp():
self.do_set_wp(filename, refresh_level)
threading.Timer(0, _do_set_wp).start()
which gets called from refresh_clock
which itself gets called from clock_thread_method
. Do I see correctly that the set_wp_throttled
method starts a new thread on every cycle? And that thread is part of the GTK window? So could it be that the thread timer is therefore part of the window object, which python or GTKor gnome implements using a timerfd inode, which then shows up on the UI as part of gnome? And could it be that the timer is started, but the thread never stopped?
I did boil it down to the section below.
If I use args = [script, wallpaper, auto, original_file, display_mode]
, the file handles get opened every time it gets called, but if I change it to args = ["echo","hi there"]
, the file handles don't get opened by gnome.
But I also tried calling just
import subprocess
args = ['/home/dolfandringa/.config/variety/scripts/set_wallpaper', '/home/dolfandringa/.config/variety/wallpaper/wallpaper-zoomed-f919fcf586e2d3637307e77a12246118.jpg','manual','/home/dolfandringa/.config/variety/Downloaded/Bing/OHR.MentonFrance_EN-US3424001829_1920x1080.jpg','os']
subprocess.check_call(args, timeout=10)
from a python cli, and then the file handles don't get opened in gnome. So it does have to do something with the combination GTK, Gnome, Python, subprocess and the script itself.
def set_desktop_wallpaper(self, wallpaper, original_file, refresh_level, display_mode):
script = self.options.set_wallpaper_script
if os.access(script, os.X_OK):
auto = (
"manual"
if not self.auto_changed
else ("auto" if refresh_level == VarietyWindow.RefreshLevel.ALL else "refresh")
)
logger.debug(
lambda: "Running set_wallpaper script %s with parameters: %s, %s, %s, %s"
% (script, wallpaper, auto, original_file, display_mode)
)
try:
args = [script, wallpaper, auto, original_file, display_mode]
# args = ["echo","hi there"]
subprocess.check_call(
args , timeout=10
)
except subprocess.TimeoutExpired:
logger.error(lambda: "Timeout while running set_wallpaper script, killed")
except subprocess.CalledProcessError as e:
logger.exception(
lambda: "Exception when calling set_wallpaper script: %d" % e.returncode
)
else:
logger.error(lambda: "set_wallpaper script is missing or not executable: " + script)
if self.gsettings:
self.gsettings.set_string("picture-uri", "file://" + wallpaper)
self.gsettings.apply()
Ok, I did manage to boil it all the way down. It has nothing to do with threading, Python, GTK, timers or variety. It can be boiled down to changing the background through gsettings. See https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5796#note_1537208.
Be aware that variety does cause my desktop to crash as a result, so the only temporary fix I have is not use variety, but it's not a code issue in variety at all.
@jlu5 thanks for adding those tags. I agree. The only thing I think on variety could be done (not taking time availability into account) is restrict the number of gsettings calls as much as possible, and maybe limit the update frequency of the desktop background. Its not a solution to the real problem, but a workaround that may make variety not as likely to trigger the issue. I think the number of gsettings calls is quite high, and as a result, I run out of open gnome open file limit quite fast (<1 day usually). I also often leave my PC on over night, and that really increases the likelihood of a crash. Not variety's fault, but still something that could be worked around maybe.
For instance, checking if the user is using dark mode first, and then only updating the background for one of them, already halves the number of gsettings calls, compared to
gsettings set org.gnome.desktop.background picture-uri "file://$WP" 2> /dev/null
gsettings set org.gnome.desktop.background picture-uri-dark "file://$WP" 2> /dev/null
And beyond those 2 calls, I feel that even though my background update frequency is 30 minutes, variety still calls the background update gsettings calls more then 2x2 an hour. Is that correct?
Hmm, I have changed my variety set_wallpaper and get_wallpaper into this just to add logging to journalctl showing what is going on: variety wallpaper scripts.zip And even though i only set the refresh rate of variety to 30 minutes, it seems all these commands get run every minute anyway, even if it's not necessary:
Aug 26 11:28:01 dolfdesktop variety[142444]: gsettgs get picure-uri
Aug 26 11:28:01 dolfdesktop variety[142451]: gsettings gnome set picure-uri
Aug 26 11:28:01 dolfdesktop variety[142457]: gsettings gnome set picure-uri-dark
Aug 26 11:28:01 dolfdesktop variety[142468]: gsettings gnome get picure-options
Aug 26 11:28:01 dolfdesktop variety[142473]: gsettings gnome set screensaver picure-uri
Aug 26 11:28:01 dolfdesktop variety[142479]: gsettings gnome get screensaver picure-options
Aug 26 11:28:01 dolfdesktop variety[142487]: gsettings mate set picure-filename
Aug 26 11:28:01 dolfdesktop variety[142490]: gsettings mate get picure-options
Aug 26 11:28:01 dolfdesktop variety[142494]: gsettings cinnamon set picure-uri
Aug 26 11:28:01 dolfdesktop variety[142497]: gsettings cinnamon get picure-options
With a memory leak on gnome, no wonder I run out of open file handles fast. Shouldn't the gsettings commands not run much less then every minute?
So looking at it better, normally of all those gsettings commands, only a single file handle is opened additionally. But it still means 1 filehandle a minute. If the desktop background actually changes (2x per hour), there are 2 more opened. And also, it runs the commands for cinnamon, mate and gnome. So I feel there is definitely some room for optimization to reduce the impact of the gnome open file handle issue
Maybe a thought is to keep track of the previous wallpaper and options that variety set it to, and only call the set_wallpaper
script if something changed, once a minute, instead of just always calling it. This could be implemented quite easily with a decorator maybe that is put around the update function in python, and keeps track of the calls to the decorated function and only runs it if the last time it was called with different arguments then are used now.
Lol, I figured out why it was updating so often, I had the "clock" feature on. So the clock feature is really a bad idea on gnome, since it updates the background incredibly often, and therefore exacerbates the gnome problem tremendously.
Maybe disable the clock feature on gnome, or at least display a warning or something
Version of Variety 0.8.9 on Fedora Workstation 36 with Gnome 42.4 with Xorg.
Describe the bug When run variety, for some reason two timerfd file handles are opened in gnome, every time variety runs through a cycle of code. I initially filed a bug report with gnome, because I didn't know what was causing it, and gnome is keeping the file handles open. But since I filed that report, I discovered it only happens while I am running variety. When I stop variety, the file handles stop increasing, and then when I start variety, more file handles get opened constantly. So it pretty clearly is related to the combination of variety and gnome. But where, I am not sure.
Specifically, what I noticed is that gnome-shell crashes because it has too many file handles open (above the single-process soft limit). When checking the open file handles on gnome with
lsof -p $(pidof gnome-shell)
, I see steadily increasing number ofa_inode [timerfd]
file handles getting opened by gnome. The number never decreases and only increases. I used a small python script to monitor this (see the gnome bug report because I can't attach it here).As I said, as soon as I stop variety, the number stops increasing, and when I start variety, it starts going up again.
When starting variety with
-v
from the terminal, it turns out, the number exactly increases by 2, every time the cycle of functions is executed in the output below. So it looks like when that code runs, 2 file handles are opened. As far as I understand it, the timerfd file handles are timers acting through file descriptors, using anonymous inodes. Not really sure about the details, but just a rough guess, could there by a python timer thread that gets started but never stopped on each cycle? It's still weird the file-handle is opened by gnome, not variety itself though. So it maybe is something that variety is triggering on gnome? But clearly 2 handles get opened by gnome on every cycle of variety.Attach Variety's log file
Desktop environment and version Gnome 42.4 with Xorg.
OS name and version Fedora Workstation 36
Attached files variety.log
Can't attach my config, so here it is pasted:
Thank you. -->