As everybdy has said, your problem is not threading.
An easy solution is to just sleep your program for as long as it takes for the file to be created.
just something like
sleep(3); while the file is being created where 3 is however long it takes will fix the problem, although its not great coding its an easy simple solution.