title: Python message passing to unique threads
body: <p>I have an application (actually a plugin for another application) that manages threads to communicate with external sensor devices. The external sensors send events to the application, but the application may also send actions to the sensors.  There are several types of devices and each has unique qualities (temperature, Pressure, etc.) that require special coding. All communications with the sensor devices is over IP. </p>
  
  <p>In the applications, I create a thread for each instance of a sensor. This is an example of the code</p>
  
  <pre><code>self.phThreadDict[phDevId] = tempsensor(self, phDevId, phIpAddr, phIpPort, phSerial, self.triggerDict)
  self.phThreadDict[phDevId].start()
  </code></pre>
  
  <p>In each thread I setup callback handlers for events sent by the sensor and then go into a loop at the end.</p>
  
  <pre><code>while not self.shutdown:
      self.plugin.sleep(0.5)
  </code></pre>
  
  <p>The threads then handle incoming events and make calls into the main thread, or the actual program that spawned the main thread. All of this works quite well. </p>
  
  <p>But, at times I also need to send requests to a specific sensor. Methods are defined in each thread for that purpose and I call those methods from the main thread. For example:</p>
  
  <pre><code>self.phThreadDict[dev.id].writeDigitalOutput(textLine, lcdMessage)
  </code></pre>
  
  <p>This also works, but I believe the code is actually executed in the main thread rather than in the thread specific to the sensor.</p>
  
  <p>My question is: What options do I have for passing work to the specific target thread and having the thread execute the work and then return success or fail?</p>