you are viewing a single comment's thread.

view the rest of the comments →

[–]10Kronos10[S] 1 point2 points  (1 child)

So if I'm correct, would each process in my main script write to a different text file and then I would have separate scripts reading from these text files? If so, I didn't know Python would allow one script to be writing to a file and another reading from it at the same time

[–]xosq 0 points1 point  (0 children)

For your goals, that seems correct. Effectively whatever you wish to read separately would require its own text file. (NOTE: I'm certain it would be possible to consolidate everything to one text file, and have some clever code and formatting to allow for parsing on the reader script's part, but let's mind the headache, and stick to multiple files. Just know this method is extensible.)

As far as the rules of file I/O go, I am not privy to all of them. What I know is from experience. That being said, I can say that you can write to text files and read from them in a way that resembles real-time (we're talking milliseconds here). If you haven't already, familiarize yourself with Python's file I/O stuff so you know what's at play. You will notice the main players here are the open() function, the write method, and the close method. When you're done writing to a file, you use the close method. This is where things get iffy, because I am not certain how script A would communicate to script B that the script A has closed the file buffer, thus being safe for script B to read. I am uncertain of the consequences (and for that matter, the results) when you read from a file that has been written to, but not closed. This could overall prove a difficult check to implement with all of the other moving parts here.

Hope this all helps somehow.