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.
I would like to have second script to print real-time data whenever it is started.
Update:
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.
Program I have initated and was working:
#!/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)
Based on that script I tried to write my own separate scripts.
First script that prints time to pipe:
#!/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 < 1000:
i = i + 1
w.write('i' + " ")
time.sleep(1)
Second script that reads time from pipe:
#!/usr/bin/python
import os, sys, time
r, w = os.pipe()
r = os.fdopen(r)
str = r.read()
print(str)
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()?