Use our timer module instead of a whole separate threading.Timer
for persistence autocheckpoint feature.
Use our timer module instead of a separate threading.Thread for
Vera gateway poller.
Ensure exceptions get logged.

Python's default behavior on an unhandled exception is to print a backtrace
to stderr. We want to make sure this ends up in the Stargate logfile and
eventually can be emailed or otherwise reported.

The first step is to install a sys.excepthook which calls logger.exception(),
so any unhandled exceptions go to the logfile.

However, threading.Thread has its own try/except block around the call to
self.run (which is what subclasses override), which... you guessed it, just
prints a backtrace to stderr. And it doesn't provide a nice mechanism to
customize this. So our second step is to interpose on threading.Thread.run
in such a way as to insert our own exception handler around it (which just
calls sys.excepthook).

There are many ways to do this; you can monkeypatch Threading.thread, or
subclass it and then monkeypatch your own subclasses, or change a ton of
client code. What I opted to do is the middle one:
- subclass threading.Thread as sg_threading.Thread
- override threading.Thread.start() with a method that renames the run
  method (presumably implemented by the client), and provides a new one
  which calls the renamed one inside our try/except block.

Then I still had to teach all the client code to use it. I opted to export
the other threading-module definitions I use (Event, RLock) via sg_threading
so that client code can use sg_threading as a dropin replacement for
threading, which makes it easier to verify that nothing is using the raw
threading module directly. And also for verification reasons, I opted to
change the client code to say "import sg_threading" instead of "import
threading", and use "sg_threading.Thread" instead of "threading.Thread".

That's all nice and explicit but there's still the danger that library
code will use threading.Thread and manage to drop exceptions on the floor.
I'm pretty surprised that Python hasn't addressed the filed bug on this
(http://bugs.python.org/issue1230540) in 6+ years. A builtin way for
threading.Thread to not swallow exceptions seems important. Anyway,
another tempting option is to pull the rename-and-extend trick on
threading.Thread itself, making it so that after sg_threading initializes,
anyone asking for threading.Thread actually gets sg_threading.Thread.
Make sure unhandled exceptions are logged via logger.exception,
so that reporter module will be able to notice them.
Report exceptions via reporter mechanism.

Teach sg_signal to interpose on logger.exception (by adding its own
logger handler which looks for report.exc_info) and now exceptions
are one of the conditions it lets clients register for.

Teach reports to use that to listen for exceptions that got logged
(which should be all unhandled exceptions), and send the exception
info via the notify mechanism.