I've been getting the "Unable to watch for file changes" warning from VS Code for many months, and tried several times to diagnose and fix it. Thanks to this Pylance bug report I finally tracked it down.
I had the top folder of my local checkouts tree in my PYTHONPATH
which has 4.3m files inside 3.1m folders. As Sabri Eyuboglu points out in their answer, VS Code recursively watches all folders listed in the PYTHONPATH
. So VS Code was consuming my entire custom 2m limit on inotify max_user_watches
. I measured this using the excellent inotify-info tool.
I actually need to import some modules from the top level of my checkouts tree, but to work around the problem I made a sub-folder with symlinks to the specific module folders that I want to be able to import, added the sub-folder to my PYTHONPATH
and removed the top-level checkouts folder from my PYTHONPATH
. Now my VS code watcher count is only 382!
It took me a while to track this down so I thought I would share my story here in case it helps others.