title: use python twisted framework to connect to multiple serial sockets
body: <p>I currently use twisted to connect to a serial device I have, using code like the following.</p>
  
  <pre><code>from twisted.internet import reactor
  SerialPort(Handler(), "/dev/ttyACM1", reactor, baudrate='9600')
  reactor.run()
  </code></pre>
  
  <p>However, I know need to extend the application to monitor for new serial devices being added (and removed).  I currently use pyinotify to look for new devices being added/removed, and this seems to work well.</p>
  
  <pre><code>class EventHandler(pyinotify.ProcessEvent):
      def process_IN_CREATE(self, event):
          ... connect to serial device
          ...
  </code></pre>
  
  <p>At the moment I seem to have several problems.  The biggest I think is that I just don't know enough about Twisted to know what the 'correct' way of doing this is.</p>
  
  <p>Currently as I have it, the pyinotify event handler kicks of in a separate thread, meaning the reactor is not running in the main thread.  Is this an issue?</p>
  
  <p>Once the first device is connected, I struggle to add a second - not least the reactor is already running by the time the second device is added.  Even if I protect that with a</p>
  
  <pre><code>if not reactor.running: 
  </code></pre>
  
  <p>the second connection doesn't add to the reactor properly (at least connectionMade, dataReceived received methods don't fire).</p>
  
  <p>If I start the reactor first, then let the pyinotify events try and add to the running reactor this doesn't seem to work either - the device does connect, but the dataReceived method never gets called.</p>
  
  <p>Basically, I'm sure there is a neat recipe for getting this to work, I just haven't been able to find it, either through Google or trial and error.  Can anybody suggest to me how I might be able to get this working?</p>
  
  <p>Thanks in advance for any help you're able to offer,</p>
  
  <p>Simon</p>