I am trying to improve the performance of my code and can't figure out how to implement multiprocessing module in it.
I am using linux (CentOS 7.2) and python 2.7
The code that I need to run in a parallel environment:
def start_fetching(directory):
with open("test.txt", "a") as myfile:
try:
for dirpath, dirnames, filenames in os.walk(directory):
for current_file in filenames:
current_file = dirpath + "/" + current_file
myfile.write(current_file)
return 0
except:
return sys.exc_info()[0]
if __name__ == "__main__":
cwd = "/home/"
final_status = start_fetching(cwd)
exit(final_status)
I need to save the meta-data of all the files (here, only filename is shown) in a database. Here I am only storing the file name in a text file.