简体   繁体   中英

Read txt file without lock in python

I am copying the new content of a.txt source file to another with the use of an offset.

with open(source, "rb") as infile:
            infile.seek(offset)
            data = infile.read()
with open(destination, "ab") as outfile:
            outfile.write(data)

Meanwhile, the source file can be updated (new rows added). Can a problem appear with this implementation? This code could lock the source file? This script runs every n seconds and the source file updates can be made at any time.

If changes are made while its running you could have problems such as missing data. By locking the file you ensure that no changes are made during execution, and that the copy matches.

Is there a reason you don't want to lock the file?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM