title: Python Unittest and Multiprocessing fail when run sequentially
body: <p>I'm attempting to create unittests for my application which uses multiple processes, but have been having strange issues when attempting to run all the tests together.  Basically when running tests individually they pass without issue but when run sequentially, such as when running all tests in the file, some tests will fail.</p>
  
  <p>What I'm seeing is that many python processes are being created but they aren't closing when the test is reported as passed.  For example if 2 tests are run that each generate 5 proceses, then 10 python processes show up in the system monitor.</p>
  
  <p>I've tried using terminate and join but neither work.  Is there a way to force a test to correctly close all processes that it generated before running the next test?</p>
  
  <p>I'm running Python 2.7 in Ubuntu 16.04.</p>
  
  <p><strong>Edit:</strong>
  It's a fairly large code base so here a simplified example.</p>
  
  <pre class="lang-py prettyprint-override"><code>from multiprocessing import Pipe, Process
  
  class BaseDevice:
      # Various methods
      pass
  
  class BaseInstr(BaseDevice, Process):
      def __init__(self, pipe):
          Process.__init__(self)
          self.pipe = pipe
  
      def run(self):
          # Do stuff and wait for terminate message on pipe
  
      # Various other higher level methods
  
  class BaseCompountInstrument(BaseInstr):
      def __init__(self, pipe):
          # Create multiple instruments, usually done with config file but simplified here
          BaseInstr.__init__(self, pipe)
          instrlist = list()
          for _ in range(5):
              masterpipe, slavepipe = Pipe()
              instrlist.append([BaseInstr(slavepipe), masterpipe])
  
      def run(self):
          pass
          # Listen for message from pipe, send messages to sub-instruments
  
      def shutdown(self):
          # When shutdown message received, send to all sub-instruments
          pass
  
  class test(unittest.TestCase):
      def setUp(self):
          # Load up a configuration file from the sample configs so that they're updated
          self.parentConn, self.childConn = Pipe()
          self.instr = BaseCompountInstrument( self.childConn)
          self.instr.start()
  
      def tearDown(self):
          self.parentConn.send("shutdown") # Propagates to all sub-instruments
  
      def test1(self):
          pass
  
      def test2(self):
          pass
  </code></pre>