I am running a MapReduce job with mrjob library and I want to record the execution time to a json
file.
I record the time with this code:
from datetime import datetime
import sys
if __name__ == '__main__':
start_time = datetime.now()
MRJobClass.run()
end_time = datetime.now()
elapsed_time = end_time - start_time
sys.stderr.write(elapsed_time)
I have to print the time to stderr
because it only works with this method.
I cannot use this code to write to json
file because my code will run in distributed mode:
data = {}
data["step1"] = elapsed_time
with open('time.json', 'w') as outfile:
json.dump(data, outfile)
How can I write the elapsed time to the JSON file in local folder with sys.stderr.write()
?