File access confusion python windows - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: File access confusion python windows (/thread-3248.html) |
File access confusion python windows - PickyBiker - May-08-2017 This problem is difficult to explain, I hope I get the idea across ok. There is a json file on a Raspberry Pi. I have a continuously running program (Visual Basic) on my windows laptop that is reading and displaying the contents of that file via ssh. It reads and updates the displayed data every 1 second. Initially, on start, it has the correct data. There is a python sketch running on the Pi that occasionally updates the pi file. The problem occurs after python updates the file, the win program does not see that data changed UNTIL I first use win explorer to view the pi file. As soon as I open the file with explorer the continuously running win program instantly shows the correct data. If I use cat on the pi, it always shows the correct data in the file. Here are the steps to make this happen: 1. Start the win program loop and the data shown is correct. 2. Update the json file with known data using a python sketch 3. The data displayed in the win program shows the OLD data, not the data written in #2 above Now the confusing part... If I use the windows explorer to view that file, instantly, #3 above shows the correct data!!! Here is the python code that updates the file # write the status file data def write_status_file(self): self.status_succeded = False while True: time.sleep(.1) print("write") print(self.data) try: with open('/home/pi/sprinkler/status.json', 'w') as self.stat: json.dump(self.data, self.stat) break except IOError as e: print "I/O error({0}): {1}".format(e.errno, e.strerror) except ValueError: print ("Can't write file status.json") Here is the VB.net subroutine that is called once per second Here is the link to the image of both programs running. The top VB.Net program shows the status file as "stat":[0] when the lower Python program shows that it has written "stat":[3]https://www.dropbox.com/s/2296hxqyj6hnum4/vb.jpg?dl=0 |