Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect File Change Without Polling [duplicate]

Tags:

python

I'm trying to use a method within a Python program to detect whether a file on the file system has been modified. I know that I could have something run on an every-5-seconds to check the last modification date off of the system, but I was curious as to whether there's an easier method for doing this, without needing to require my program to check repeatedly.

Does anyone know of such a method?

like image 719
Thomas Ward Avatar asked Apr 21 '11 01:04

Thomas Ward


1 Answers

watchdog

Excellent cross platform library for watching directories.

From the website

Supported Platforms

  • Linux 2.6 (inotify)

  • Mac OS X (FSEvents, kqueue)

  • FreeBSD/BSD (kqueue)

  • Windows (ReadDirectoryChangesW with I/O completion ports; ReadDirectoryChangesW worker threads)

  • OS-independent (polling the disk for directory snapshots and comparing them periodically; slow and not recommended)

I've used it on a couple projects and it seems to work wonderfully.

like image 144
nemith Avatar answered Oct 10 '22 15:10

nemith