Commit 4da38fa2 authored by Sebastien Robin's avatar Sebastien Robin Committed by Julien Muchembled

BT: prevent conflicts when several processes call genbt5list in parallel

Cherry picked from commits:
  cacea29b
  a4555829
  073e3e4b
parent db6a2d07
......@@ -213,14 +213,16 @@ def main(dir_list=None, **kw):
for d in dir_list:
bt5list = generateInformation(d, **kw).getvalue()
d = os.path.join(d, 'bt5list.new')
# add pid in filename to avoid conflicts if several process calls genbt5list
destination_path = os.path.join(d, 'bt5list')
temporary_path = destination_path + '.new.%i' % os.getpid()
try:
with open(d, 'wb') as f:
with open(temporary_path, 'wb') as f:
f.write(bt5list)
os.rename(d, d[:-4])
os.rename(temporary_path, destination_path)
finally:
try:
os.remove(d)
os.remove(temporary_path)
except OSError:
pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment