Closed timofurrer closed 8 years ago
Click already has a custom open_file() method which allows atomic behaviour: http://click.pocoo.org/6/api/#click.open_file.
Maybe we can make use of it.
I'll have a look at clicks open_file
.
click does not support atomic appending. See https://github.com/mitsuhiko/click/blob/master/click/_compat.py#L434 They suggest to open in w-mode and copy data explicitly.. What do you think about that?
Yea, that's basically what you have to do. Copy the file, append to new file, rename back.
-Jeremy
Insert PGP signature here.
On Feb 8, 2016, at 9:46 AM, Timo Furrer notifications@github.com wrote:
click does not support atomic appending. See https://github.com/mitsuhiko/click/blob/master/click/_compat.py#L434 They suggest to open in w-mode and copy data explicitly.. What do you think about that?
— Reply to this email directly or view it on GitHub.
I've updated the PR. You can easily test it with this:
>>> with twtxt.helper.atomic_write("testfile", "a") as f:
... f.write("Hallo")
... raise AttributeError("FAILED")
...
5
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
AttributeError: FAILED
>>>
@kitchen do you agree with this implementation?
Implement atomic writing for the local tweets.
Refs #34