[1.7.x] Fixed pyinotify performance regression in 15f82c7011

Refs #9722. Thanks Tim Graham for the review.
Backport of 6d302f639 from master.