Hello,
I have discovered a bug where I got read errors for language files (ERROR:
Syntax error in /home/... .../languages/en-gb.py). After some debugging I
found out that the cause is that the file is being read while it is half
written by another thread (or process). There is a lock for it, but the
full contents of the file is not written before close (which is after the
unlock). By adding a flush before the unlock in write_dict, I don't get the
error anymore.
I discovered the error by running system tests with Selenium in parallel, I
suppose there is a simpler way to trigger the bug. ;-)
My patched write_dict in languages.py:
def write_dict(filename, contents):
try:
fp = open(filename, 'w')
except IOError:
if not is_gae:
logging.warning('Unable to write to file %s' % filename)
return
portalocker.lock(fp, portalocker.LOCK_EX)
fp.write('# coding: utf8\n{\n')
for key in sorted(contents):
fp.write('%s: %s,\n' % (utf8_repr(key), utf8_repr(contents[key])))
fp.write('}\n')
fp.flush()
portalocker.unlock(fp)
fp.close()
Regards
Anders