[Twisted-Python] "Directory triggers" with kqueue using Twisted? (on MacOS X / FreeBSD)
Hello, recently I read something about the "kqueue" event notification mechanism built into FreeBSD and that it would allow to receive notification when filesystem contents change. Would this mechanism allow to implement a similar function as database triggers for a filesystem, i.e. write a script that does something with files that are added to, modified in or deleted from a certain directory without having to poll the filesystem all the time? Folder actions allow such things on MacOS X, but Applescript is slow and I would prefer Python anyway. ;-) If so, is there a way to write such scripts in Python using Twisted? TIA, Best regards Wolfgang Keller
On Jan 13, 2005, at 15:40, Wolfgang Keller wrote:
recently I read something about the "kqueue" event notification mechanism built into FreeBSD and that it would allow to receive notification when filesystem contents change. Would this mechanism allow to implement a similar function as database triggers for a filesystem, i.e. write a script that does something with files that are added to, modified in or deleted from a certain directory without having to poll the filesystem all the time? Folder actions allow such things on MacOS X, but Applescript is slow and I would prefer Python anyway. ;-) If so, is there a way to write such scripts in Python using Twisted?
Actually Folder Actions don't allow this. I am relatively certain that they are implemented entirely in Finder. They *might* be hooked into at the CoreServices/Carbon APIs, but DEFINITELY NOT the BSD level APIs (in Mac OS X 10.3 and earlier anyway). The kernel in Mac OS X 10.3.0 supports kqueue, so you can use it for this sort of thing -- but Finder still polls. I do not know what is necessary to integrate this with Twisted, though. There is some support for kqueue in Twisted, but last I remember you need to download and patch some years-old extension and compile it in order to get that to work. Another thing of interest to you might be FAM <http://oss.sgi.com/projects/fam/>. -bob
On Thu, 2005-01-13 at 15:51 -0500, Bob Ippolito wrote:
The kernel in Mac OS X 10.3.0 supports kqueue, so you can use it for this sort of thing -- but Finder still polls.
James was showing some docs that said it doesn't actually support the file notification stuff currently.
On Jan 13, 2005, at 16:20, Itamar Shtull-Trauring wrote:
On Thu, 2005-01-13 at 15:51 -0500, Bob Ippolito wrote:
The kernel in Mac OS X 10.3.0 supports kqueue, so you can use it for this sort of thing -- but Finder still polls.
James was showing some docs that said it doesn't actually support the file notification stuff currently.
I've seen it used in GraphViz and ReSTedit, so that's simply not true (for files anyway, not sure about directories). -bob
On Jan 13, 2005, at 16:32, Bob Ippolito wrote:
On Jan 13, 2005, at 16:20, Itamar Shtull-Trauring wrote:
On Thu, 2005-01-13 at 15:51 -0500, Bob Ippolito wrote:
The kernel in Mac OS X 10.3.0 supports kqueue, so you can use it for this sort of thing -- but Finder still polls.
James was showing some docs that said it doesn't actually support the file notification stuff currently.
I've seen it used in GraphViz and ReSTedit, so that's simply not true (for files anyway, not sure about directories).
Additionally, Apple has sample code that demonstrates this feature: http://developer.apple.com/samplecode/FileNotification/ FileNotification.html -bob
On Thu, 2005-01-13 at 16:36 -0500, Bob Ippolito wrote:
Additionally, Apple has sample code that demonstrates this feature: http://developer.apple.com/samplecode/FileNotification/ FileNotification.html
Neato. Who wants to fix up kqreactor, and then write a cross-platform file notification API that uses kqueue when available?
On Thu, 2005-01-13 at 16:56 -0500, Itamar Shtull-Trauring wrote:
On Thu, 2005-01-13 at 16:36 -0500, Bob Ippolito wrote:
Additionally, Apple has sample code that demonstrates this feature: http://developer.apple.com/samplecode/FileNotification/ FileNotification.html
Neato. Who wants to fix up kqreactor, and then write a cross-platform file notification API that uses kqueue when available?
*BZZT*! You did not state your response in the form of a new item in the tracker ;-)
On Thu, 13 January 2005 at 16:56:10 -0500, Itamar Shtull-Trauring wrote:
Neato. Who wants to fix up kqreactor, and then write a cross-platform file notification API that uses kqueue when available?
Actually I'm playing with kqreactor right now, but before starting serious work on it need to settle on new py-kqueue API first. Results of first attempts to change kqreactor are very promising. For example reactor's Waker implemented using kqueue's timer is much simpler and way faster than FIFO ping-pong. Timers can be used for CallLater as well... Michal
On Mon, 2005-01-17 at 20:52 +0100, Michal Suszko wrote:
simpler and way faster than FIFO ping-pong. Timers can be used for CallLater as well...
Make sure kqueue uses a decent algorithm. Using glib timers for callLater is *slower* than using Python for large numbers, since glib uses a stupid O(n) algorithm. Keep us posted on your work, it sounds very useful.
Am Mon, 17 Jan 2005 20:52:14 +0100 schriebst du:
On Thu, 13 January 2005 at 16:56:10 -0500, Itamar Shtull-Trauring wrote:
Neato. Who wants to fix up kqreactor, and then write a cross-platform file notification API that uses kqueue when available?
Actually I'm playing with kqreactor right now, but before starting serious work on it need to settle on new py-kqueue API first.
Did you check out the 1.4 version of PyKQueue? http://ox.eicat.ca/~dgilbert/files/PyKQueue.html Best regards Wolfgang Keller
On Mon, 17 January 2005 at 22:51:55 +0100, Wolfgang Keller wrote:
Am Mon, 17 Jan 2005 20:52:14 +0100 schriebst du:
On Thu, 13 January 2005 at 16:56:10 -0500, Itamar Shtull-Trauring wrote:
Neato. Who wants to fix up kqreactor, and then write a cross-platform file notification API that uses kqueue when available?
Actually I'm playing with kqreactor right now, but before starting serious work on it need to settle on new py-kqueue API first.
Did you check out the 1.4 version of PyKQueue?
Yes, I'm in contact with David. BTW If anyone uses PyKQueue I can send my WIP to test. Michal
participants (5)
-
Bob Ippolito
-
Glyph Lefkowitz
-
Itamar Shtull-Trauring
-
Michal Suszko
-
Wolfgang Keller