title: Python - how to share real-time data with another script
body: <p>I am trying to find easiest way to share real time variable from one script to another. First script will read seonsor data and other will make calculations based on real-time data from the first script. I want to run them separetly. I want to be able to kill second script and run it again without any problems.</p>
  
  <p>I would like to have second script to print real-time data whenever it is started.</p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>I have finaly got some time to play with os.pipe(). I have managed to run some scripts that use os.fork() but when I tried to split one script into two separate programs I start haveing some issues.</p>
  
  <p>Program I have initated and was working:</p>
  
  <pre><code>    #!/usr/bin/python
       import os, sys
       r, w = os.pipe() 
       processid = os.fork()
       if processid:
             os.close(w)
             r = os.fdopen(r)
             print("Parent reading")
             str = r.read()
             print("text =", str)   
             sys.exit(0)
       else:
             os.close(r)
             w = os.fdopen(w, 'w')
             print("Child writing")
             w.write("Text written by child...")
             w.close()
             print("Child closing")
             sys.exit(0)
  </code></pre>
  
  <p>Based on that script I tried to write my own separate scripts.</p>
  
  <p>First script that prints time to pipe:</p>
  
  <pre><code>   #!/usr/bin/python
     import os, sys, time
     stdout = sys.stdout.fileno()
     r, w  = os.pipe()
     #os.close(r)
     w = os.fdopen(w, 'w')
     i = 0
     while i &lt; 1000:
           i = i + 1
           w.write('i' + " ")
           time.sleep(1)
  </code></pre>
  
  <p>Second script that reads time from pipe:</p>
  
  <pre><code>   #!/usr/bin/python
  
     import os, sys, time
     r, w = os.pipe()
     r = os.fdopen(r)
     str = r.read()
     print(str)
  </code></pre>
  
  <p>When I try to run my scripts nothing happens. Any suggestions what am I doing wrong? Maybe I missed some details about standard input and output and os.pipe()?</p>