In python, I need to record some results in a file. The results are generated by a function in a loop. The following code shows an example:
with open('result_file', 'w') as file:
for i in xrange(10000):
result = somethingTakesTime()
file.write(str(result), '\n')
Function somethingTakesTime()
is time costly. I would like to check the result_file even the program is still working. However, with the current Python 2.7, I only can get the result after the for loop finish. Is there any method that I can see the result (in result_file) even the code is still working?