If the Mercurial process fork()s, the Python thread ID remains
unchanged. The previous code for returning a SQLite connection would
recycle the existing connection among all children.
Mercurial can fork() when performing working directory updates.
For reasons I don't fully understand, the recycling of even a
read-only SQLite connection was resulting in Python raising a
"DatabaseError: database disk image is malformed" exception. This
message comes from the bowels of SQLite. I suspect there is some
internal client state in the SQLite database somewhere and having
multiple clients race to update it results in badness. Who knows.
This commit teaches the "get a SQLite connection" logic to also
verify the PID matches before returning an existing connection.