Like should I manually add locks when futures write the same file to guarantee they write it one by one?
I mean the concurrent.futures.ThreadPoolExecutor
And I know the java executor is thread safe
An Example:
def task():
with open("somefile", "a") as fh:
fh.write(part_of_data)
do_something()
with open("somefile", "a") as fh:
fh.write(other_data)
In this example, I want to make sure each other_data is appended next to part_of_data when tasks are executed in ThreadPoorExecuter
I'm not sure the with statement is atomic operation, but if not, the executor should also guarantee the file is open and closed correctly