I have a simple function that polls a folder and loads a new file when one is detected:
raw = []
def poll_file(mydir, raw)
while 1:
after = dict([(f, None) for f in os.listdir(mydir)])
added = [f for f in after if f not in before]
# New File
if added:
raw.append(numpy.loadtxt(mydir + added[0]))
# Set Trigger
if raw[-1] > 5:
trigger = 1
return trigger
In my main script, at some points in time, I will want to wait until trigger
turns to '1', but during times I don't care what trigger
is, I want my variable raw
to continue to be appended with new data from the new files.
So, I have two questions.
How do I start running a python function in the background?
How do I setup
trigger
as a global variable that can be read in my main script and then reset to 0, like:while trigger != 1: # do nothing until trigger == 1 trigger = 0
How do I stop the constant function in the background and save
raw
to a pickle file in the end? I assume I would set it as a global variable.