Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #109033 > unrolled thread

Re: [pyinotify] help required to send only one mail for chunk of events

Started byChris Angelico <rosuav@gmail.com>
First post2016-05-24 10:09 +1000
Last post2016-05-24 10:09 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [pyinotify] help required to send only one mail for chunk of events Chris Angelico <rosuav@gmail.com> - 2016-05-24 10:09 +1000

#109033 — Re: [pyinotify] help required to send only one mail for chunk of events

FromChris Angelico <rosuav@gmail.com>
Date2016-05-24 10:09 +1000
SubjectRe: [pyinotify] help required to send only one mail for chunk of events
Message-ID<mailman.41.1464048578.20402.python-list@python.org>
On Tue, May 24, 2016 at 6:20 AM, Mohan L <l.mohanphy@gmail.com> wrote:
> I wanted to send an email notification with content of logfile after 15
> mins on any change. The idea is I want to send only one mail for chunk of
> events.Say for example, I want to send only one email when some one extract
> a tar.gz file in watched directory.

I'm ignoring your actual code, because the formatting is all messed up
- your mail/news client appears to have destroyed your indentation.
But there are two straight-forward ways of doing what you want here:

1) Whenever there's a change, wait fifteen minutes, then send an email
with all the recent changes.

2) Whenever there's a change, check to see when you last sent an
email, and if it's more than fifteen minutes ago, send one
immediately.

I'm not entirely sure how to interpret your "after 15 mins", but my
guess is that it's one of the above.

Oh, I lied. I am looking at your code, just a bit.

> try:
> import pyinotify
> except:
> print "pyinotify not installed"
> sys.exit(1)

Don't do this. Ever. If you want to use pyinotify, there's one thing to do:

import pyinotify

If that doesn't work, Python will print an error message and then exit
1, so having code like this is at best just duplicating what already
exists. The default message is far more helpful, though, so you're
destroying information - a lot of it. You use a bare 'except:' further
down, too; again, don't. Figure out _exactly_ what exception you're
intending to catch, and catch that.

Finally: Consider upgrading to Python 3. With a script this size, I
doubt there's anything holding you on Python 2 (the two primary
dependencies are pyinotify and the sending of emails, both of which
are available on Py3), so this would be well worth porting.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web