Element Tree Fetching from Mem and not Storage

There is a different branch that uses lists instead of a DriverStint class

Here I have a program that’s intended to read a .xml file output, that’s overwritten every 0.5 sec by a separate program. My script needs to take the initial input and compare certain values to the overwritten ones to watch for changes. Specifically when the difference of DriverStint.pit_time and get_stint_info()...['total_time'] is over 7200000ms (2 hours) I want it to trigger DriverStint.over_stint.

The problem I’m having is that when i start the program it fetches the data i want via e-tree, but it will not continue to fetch the data, it will only return the initial .xml file state even if i call get_stint_info() again in a while True loop. So any changes/overwrites that happen are not getting read by my script, so nothing can get triggered b/c its just comparing 2 copies of the xml file…

How can I continuously fetch updated data from an .xml while its being overwritten every ~0.5secs


updated link

This happens because the file is parsed (read) in these lines:

tree = ET.parse('Testresults.xml')  # use 'current.xml' not results
root = tree.getroot()

which are executed on the beginning of the script execution. This is why multiple executions of function get_stint_info will yield the same results - content of the file has changed, but the file is already parsed (and stored in tree and root variables), so in the context of the get_stint_info nothing has changed.

I would probably tackle this problem in this way:

  1. Move parsing of the file into the get_stint_info function;
  2. Use watchdog to monitor the modifications of the files;
  3. On the change of the file content (watchdog will provide event listener) call get_stint_info function.

Thank you!
It seems simple now but I hadn’t even realized that’s what was happening.
Really appreciate the help!

From the fresh perspective it is always easier to spot things like that :panda_face:

You’re welcome :slight_smile: