test-queue-worker-reload: Add wait to avoid race condition.

The autoreload code of Django works by looping over the files associated
with all the loaded modules. This loop is run after every 1 second. If
the file is found for the first time by the loop, it is assumed that the
file is new and is not modified between the time it is loaded and is
checked by the loop. This assumption is the source of a race condition.

We can either implement a more sensitive version of the loop or we can
just allow enough time to the Django loop to touch every file at least
once.

For the time being, we are going with the second option.
This commit is contained in:
Umair Khan 2018-01-05 12:56:14 +05:00 committed by showell
parent e68adab75d
commit 6259390f40
1 changed files with 10 additions and 0 deletions

View File

@ -70,6 +70,16 @@ if __name__ == '__main__':
logfile.close()
sys.exit(1)
# The autoreload code of Django works by looping over the files associated
# with all the loaded modules. This loop is run after every 1 second. If
# the file is found for the first time by the loop, it is assumed that the
# file is new and is not modified between the time it is loaded and is
# checked by the loop. This assumption is the source of a race condition.
# We can either implement a more sensitive version of the loop or we can
# just allow enough time to the Django loop to touch every file at least
# once.
time.sleep(1.1)
# Removing all data from the server log file.
logfile.truncate(0)
logfile.seek(0)