How to access the file shared between different accessors?
One mechanism would be to have the producer roll the file to a new name (maybe with HHMMSS suffix) every so often, and have the consumer only process the file once it has been rolled to the new name.  Maybe every 5 minutes?
Another mechanism would be to have the consumer roll the file itself and have the producer notice that the file has rolled and to re-open the original file name.  So the consumer is always consuming from output.consume and the producer is always writing to output or something.

Every time a line is written to the file, the producer makes sure that output exists.
When a consumer is ready to read the file, he renames output to output.consume or something.
The producer notices that the file output no longer exists so he reopens it for output.
Once the output file is re-created the consumer can process the output.comsume file.
I have code written on Java which writes all data to the file and then I have python script which handles this data.
They run completely separately and python script can be run by schedule but it also removing handled records from the file.
The question is in implementation for the access to the file when java code from first process will try to write something and python code from second process will try to remove handled record?
First thought was to have .lock file physically created when one of the processes updating the file but perhaps there are some other solutions to consider?
Thank you.