Hello guys, I was wondering if it is possible to execute the 5 other python file simultaneously/concurrently with our main python file waiting for all the 5 file to be executed first then continues with its execution... the problem that arise is that when I try to do multi-threading, our main thread continues to execute so our main python file finish executing without waiting for the other python file to terminate.
# main.py
# Execute each script
print("\nFetching information from lemauricien.mu\n")
exec(open("A_Reading_File.py").read())
print("\nFetching information from Actu.mu\n")
exec(open("B_Reading_File.py").read())
print("\nFetching information from defimedia.info\n")
exec(open("C_Reading_File.py").read())
print("\nFetching information from lexpress.mu\n")
exec(open("D_Reading_File.py").read())
print("\nFetching information from ionnews.mu\n")
exec(open("E_Reading_File.py").read())
# Merging information from multiple files into Results.txt
# List of input files
input_files = [
"leMauricien_info.txt",
"ActuFile.txt",
"DefimediaFile.txt",
"expressFile.txt",
"IonNewsFile.txt"
]
# Output file
output_file = "Results.txt"
# Open the output file in write mode
with open(output_file, "w", encoding="utf-8") as outfile:
# Iterate through each input file
for filename in input_files:
# Open each input file in read mode
with open(filename, "r", encoding="utf-8") as infile:
# Read the content of the input file
file_content = infile.read()
# Write the content to the output file
outfile.write(file_content)
# Add a separator between the content of different files
outfile.write("\n--- End of {} ---\n\n".format(filename))
print("Merge complete. Results saved in", output_file)