I have two python scripts, for arguments sake lets call them A
and B
. Both A
and B
contain a while loop which runs indefinitely. They show live feeds of two different data collection devices. Script A
is able to accept key presses. Now, what I would like to do is for script B
to identify a keypress in script A
. Each script is executed in a different terminal.
How am I able to communicate as fast as possible between the two python scripts? How am I able to pass a string
or something similar from script A
to script B
without using a dummy file? With a dummy file I am regarding to a file which is constantly read by script B
and written to by script A
when a keypress has been registered.
Can someone point me in the right direction?
Both scripts are showing live feeds of data using the while loops. It is therefore very important that neither script is stalling or waiting for something.
Script A:
import sys
import numpy
import select
def heardEnter():
i, o, e = select.select([sys.stdin], [], [], 0.0001)
for s in i:
if s == sys.stdin:
input = sys.stdin.readline()
return True
return False
while True:
if heardEnter():
print "A: Pressed enter"
Script B:
while True:
A_press_enter = None
if A_press_enter == "Enter":
print "B: Enter was pressed in script A"