Skip to content

wxGUI: Share watchdog Observer to fix FSEvents RuntimeError - #7677

Merged
petrasovaa merged 2 commits into
OSGeo:mainfrom
saket0187:Fix-runtime-error-watchdog
Jul 18, 2026
Merged

petrasovaa merged 2 commits into
OSGeo:mainfrom
saket0187:Fix-runtime-error-watchdog

Conversation

@saket0187

Copy link
Copy Markdown
Contributor

Fixes #7652

  • Fixes RuntimeError: Cannot add watch ... - it is already scheduled on macOS by replacing per-instance Observer objects with a single class-level _shared_observer across MapsetWatchdog instances.
  • Adds weakref.WeakSet instance tracking (_instances) so ScheduleWatchCurrentMapset() can schedule event handlers for all active GUI components.

I have used Claude for this.

@github-actions github-actions Bot added GUI wxGUI related Python Related code is in Python labels Jul 12, 2026
@petrasovaa petrasovaa moved this from Todo to In Progress in GRASS Google Summer of Code 2026 Jul 12, 2026
@petrasovaa

Copy link
Copy Markdown
Contributor

Have you figured out why this is even necessary? It would be good to understand the source of the problem. Could you please confirm you tested it?

@saket0187

Copy link
Copy Markdown
Contributor Author

Could you please confirm you tested it?

Yes, I tested it before creating the PR, and it does fixes the issue.

Have you figured out why this is even necessary? It would be good to understand the source of the problem. Could you please confirm you tested it?

From what I was able to understand, Originally MapsetWatchdog only monitored the Layer Manager / Main Window (GMFrame), which is why the docstring mentions "Schedules 1 watches (raster)" I think.

self._mapset_watchdog = MapsetWatchdog(
            elements_dirs=(("raster", "cell"),),

When the Data Catalog (DataCatalogTree) was added alongside GMFrame, it initialized its own MapsetWatchdog. When interacting with layers/mapsets (_loadItemsDone() / _updateAfterMapsetChanged()), It calls ScheduleWatchCurrentMapset(), creating a separate watchdog.Observer() monitoring the exact same directories that GMFrame's observer is already watching.

On Windows/Linux, It allows two separate observers in the same process to watch the same directory independently without error.
On macOS (FSEvents), watchdog uses a process-global C library that forbids duplicate watches. When the second observer tries to watch a directory that the first observer is already monitoring, it throws RuntimeError: ... already scheduled and stops receiving file updates.

Comment thread gui/wxpython/core/watchdog.py Resolved
@saket0187
saket0187 requested a review from petrasovaa July 17, 2026 17:37
@petrasovaa
petrasovaa enabled auto-merge (squash) July 17, 2026 19:19
@petrasovaa
petrasovaa merged commit e37a2aa into OSGeo:main Jul 18, 2026
26 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in GRASS Google Summer of Code 2026 Jul 18, 2026
@github-actions github-actions Bot added this to the 8.6.0 milestone Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GUI wxGUI related Python Related code is in Python

Development

Successfully merging this pull request may close these issues.

[Bug] RuntimeError (FSEventsEmitter) on GUI startup

2 participants