looking-glass: replace pyinotify with Gio.FileMonitor#13898
Open
Fantu wants to merge 1 commit into
Open
Conversation
pyinotify has been unmaintained upstream since 2015 and it imports asyncore, which was removed from the Python standard library in 3.12; it currently keeps working only because distributions pull in a third-party backport of that module. Gio.FileMonitor provides the same functionality through python3-gi, which Cinnamon already depends on, so the log file watcher in Looking Glass loses a dependency instead of trading it for another one. It also fixes a latent thread-safety problem: pyinotify's ThreadedNotifier dispatched the callbacks from its own thread, so the log view (and therefore Gtk.TextBuffer) was refreshed from outside the main loop. Gio.FileMonitor emits "changed" on the thread-default main context. The existing 500 ms rate limiting is unchanged and also absorbs the changed/changes-done-hint pair GFileMonitor emits for a single write. Also drop python3-pyinotify from debian/control and pyinotify from the pylint extension whitelist, as nothing else uses it. Assisted-by: Claude Code:claude-opus-4-8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cinnamon-looking-glass.pyis the only thing in Cinnamon still using pyinotify, for the file watcher tabs ("Actions → Add File Watcher") that tail a log file.pyinotify is a problem now:
import asyncoreat module level, andasyncorewas removed from the Python standard library in 3.12. It still imports today only because distributions ship a third-party backport of that module as an extra dependency (Debian addedpython3-pyasyncoretopython3-pyinotifyfor exactly this reason);Gio.FileMonitordoes the same job and comes from python3-gi, which Cinnamon already depends on, so this drops a dependency rather than trading it for another one — no new build or runtime requirement, andGiowas already imported in this file.There is a second, smaller benefit.
pyinotify.ThreadedNotifierruns its own thread and calledget_updates()from there, so the log view — and thereforeGtk.TextBuffer.set_text()inupdate()— was being driven from outside the main loop.Gio.FileMonitoremitschangedon the thread-default main context, so everything now stays on the main loop.What changed
FileWatchHandler(thepyinotify.ProcessEventsubclass) is gone; its fourprocess_IN_*methods all did the same thing and collapse into a singleon_file_changed()callback.FileWatcherViewmonitors the file withGio.File.new_for_path(filename).monitor_file()and cancels the monitor on destroy, instead of starting/stopping aThreadedNotifier.pyinotifydropped fromdebian/controland from the pylintextension-pkg-whitelist.The
IN_CLOSE_WRITE | IN_CREATE | IN_DELETE | IN_MODIFYmask maps onto the defaultGFileMonitorevents (changed,changes-done-hint,created,deleted), all of which just trigger a refresh. The existing 500 ms rate limiting inget_updates()is untouched and also absorbs thechanged+changes-done-hintpair thatGFileMonitoremits for a single write.Testing
Tested on a Debian sid VM with Cinnamon 6.6.8, driving
FileWatcherViewdirectly on the running session: appending to the watched file refreshes the text buffer exactly as before, and the monitor is cancelled when the view is destroyed. Running the same test against the unmodified file shows the thread count going from 1 to 2 (theThreadedNotifier), while withGio.FileMonitorit stays at 1.Also checked manually from the UI: Looking Glass → Actions → Add File Watcher on a log file, the tab updates and auto-scrolls as before.