Question: The below Linux shell script will give you a file1.txt containing one million random numbers: for i in {1..1000000} do echo $RANDOM >> file1.txt done

The below Linux shell script will give you a file1.txt containing one million random numbers:

for i in {1..1000000} do echo $RANDOM >> file1.txt done

The below Python code takes each line (containing a random number) from above file file1.txt multiply that number by "2" and stores the result in file2.txt:

f1 = open("file1.txt",'r') all_lines = f1.readlines()

f2 = open("file2.txt",'w') dn = 0

for l in all_lines: dn = int(l) * 2 f2.write(str(dn) + ' ')

f2.close()

Need to rewrite the above Python code to implement multi-threading and parallelism. For example if the computer has two cores then break the file1.txt into two parts lets say file1_a.txt and file1_b.txt and Python code must run on both the parts in parallel.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!