title: Multiprocessing? Threading? infinite loops? what should I do?
body: <p>I'm trying to understand the most effective way of solving the following issue. I have python code pooling in data from multiple sources (using pyserial). My goal is to generate a pandas table containing all this data that I have collected (from three sources). All the data has to be collected simultaneously so I will either have to use threading or multiprocessing and be able to have all the programs start and stop simultaneously. This is the general idea of my code:</p>
  
  <pre><code>User_inputs
  ###########
  functions
  ###########
  Port/Serial Misc.
  ###########
  loops (can be defined in functions) e.g:
  
  def lightloop():
     data = { 'light': []}
     df = pd.DataFrame(data, columns=[ 'light'])
     while True:
         arduino.reset_input_buffer()
         value = float(str(arduino.readline()))#everysecond
         df = df.append({'light': value}, ignore_index=True)
         print df
         time.sleep(1)
         if len(df.index) &gt; 5:
             break  
     return df
  
  ###########
  code that will analyze the data collected in the loops e.g
  
  datatime = {'time': []}        
  df2 = pd.DataFrame(datatime, columns=[ 'time'])
  for i in range(len(df['light'])):      
      df2 = df2.append({'time': i}, ignore_index=True)
      df['time'] = df2['time']
  
  print df
  df.to_csv('~/Downloads/test.csv', sep='\t')
  plt.scatter(df['time'], df['light'])
  afont = {'fontname':'Avenir Book'}
  mfont = {'fontname':'Menlo Regular'}
  plt.title('',**mfont)
  plt.ylabel('light', **afont)
  plt.xlabel('Time [Second]', **afont)
  plt.style.use('ggplot')
  plt.savefig(os.path.expanduser('~/Downloads/test.png'), dpi = 150)
  </code></pre>
  
  <p>What would  be the best way of going about this? I have looked into threading and it isn't very straightforward and complicates my code greatly, I'm also unable to stop the threads such that my data analysis code runs. </p>