title: Python fast calculating and slow Serial writing : Multithread or Multiprocess
body: <p>I have a robotics project, basically a path tracking problem.
  In PC, a reference generation algorithm is implemented in Python3.65. The algorithm takes Indoor GPS data and use these continuously-updated data to calculate the reference path for a robot-car. Of course, the algorithm runs in a 
  <strong><em>while True:
     ....</em></strong>
  framework.
  The algorithm can work well only if the sampling frequency is quite high, say 0.001s. 
  However, the problem is that, after calculating the reference path, the path info needs to be written to Serial port of the PC, byte by byte, via Serial.write(). 
  This serial.write() function is still a for loop. And this writing process is very slow (more than 0.02s for 16 bytes). If the for loop is included in the while True: framework, something like：</p>
  
  <hr>
  
  <pre><code>while True:
    Data = Ref_generation()
    Bytes_Full = Float_2_Bytes_List(Data)
    for ele in Bytes_Full:
      Serial.write(ele)  # VERY SLOW!!!
    sleep(0.001)
  </code></pre>
  
  <hr>
  
  <p>Then, the Data can not be calculated correctly since the cycle period is much longer than 0.001s. </p>
  
  <p>In a nutshell, how can I separate the fast calculating algorithm from the slow serial.wtite()? I tried multithreads, but not works. </p>
  
  <p>Anyhelp will be appreciated, thanks a lot!</p>