newbie question about event based programming
Philip Swartzleonard
starx at pacbell.net
Mon Apr 8 14:11:36 EDT 2002
Alex Martelli || Mon 08 Apr 2002 03:24:59a:
> ashimali at btinternet.com wrote:
>
>> Hello All,
>> I'm wondering if there is a way to put an "event listener" (sorry for
>> the Java terminology), on a directory. What I'm trying to do is have
>> a python script be invoked on files whenever new file/s are
>> copied/moved to a particular directory. Any tips gratefully recieved!
>> Cheers Adam
>
> That depends, first of all, on the functionality of your underlying
> operating system -- for example, Windows lets you do that (if your
> event loop is coded in a powerful enough way, but that's another
> issue). I don't believe there is any cross-platform way -- it's not
> up to the language, alas. The best you can achieve in most platforms
> would be to "poll", say every second, to see if the directory was
> modified. Even just getting a function of yours called every second
> is hard to arrange in a cross-platform way. Fine if you're using
> some given GUI toolkit, such as Tkinter (it has an .after method to
> schedule a function call, and you need to call it again in the
> scheduled function to get periodic repetitions), but there's no way
> that works across platforms and toolkits.
>
> Event-driven programming is a great thing, but it's not supported
> as well as it could and should be across every platform and toolkit
> in the world:-(.
If you just want it to inform you when something adds files to the
directory, and you don't need split second response... I made a program
to monter a network in directory a while ago, and it did something like
this:
while 1:
self.check_dir()
os.sleep(60) #I think that's hte sleep i used
I can't seem to find the flie anymore though -- I gave up on it because
I couldn't get the systray icons to display properly =).
--
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com
More information about the Python-list
mailing list