Switch to using threads instead of multiprocessing.

The code becomes more complex, but seemingly easier to deal with. Certainly
there are less errors when quitting and less chances of orphans.