buffering experiments, since I want to get IPC working.
Typo; make the backend socket actually use $TABLE not $table in its name
Fix my use of 'trap" so that replicate_server kills its children smoothly.

This is better than manually tracking all children it spawns, even though there is only one, at the moment.
*undo* my forced-cd in thre postgres client.sh

This made test.psql annoying to use, because client.sh would basically lie
about where it was running from, and test.psql relies on \COPY being able
to use relative paths.
Clean up replicate.py's shutdown conditions

1) write the replication as the main thread as originally, and
   spawn the stdin-watching process as the subthread
2) write a shutdown() function which makes what's going on really explicit
3) catch signals which additionally should cause cleanups (I missed this before)

Also, wrap the OS X workaround in an if and give feedback from it.
switch to just using a global socket for shutdown signalling

globals are bad usually, but in this one case, where we need it in
something else global--a signal handler--it makes sense.
Rearrange for readability
Finally adapt replicate() to match local indentation

replicate() originally existed in replicate.pysql, where I chose to use 2-space indents and had to name table "_table"
Make sure `pkill replicate.py` also takes down the socket

The trick was that alivethread() was holding the program (and hence
its file descriptors and hence socat and hence websockify) open after
the main thread had exited.

This is exactly that Thread.daemon solves.

I love easy fixes.
Defensively unregister clients that go missing

I already made it so that unregister() happens
 if the front end websocket closes / replicate.py quits (e.g. via ctrl-c)
 if replicate.py is kill -TERM or kill -INT or kill -QUIT'd
(i.e. soft kills)

this makes unregister() happen
 if replicate.py is kill -KILL'd or kill -ABRT'd
but since those are hard kills, this case is only detected
on the next write to the watched table.
Clean up the trigger in unregister()

This commit is sort of wordy because SQL.
All it does is:
 table.refcount--;
 if table.refcount == 0:
  delete table.trigger