Question: This week we will explore using Python 3 and multiple processes to sort the contents of multiple files. You should only need to use the
This week we will explore using Python 3 and multiple processes to sort the contents of multiple files. You should only need to use the modules that come included with Python 3. While this could be accomplished using a single process, the purpose is to explore how to create multiple processes and have the processes communicate with each other. You are to submit a Python 3 script called sorter.py. This script should accept a --files parameter that accepts multiple files to be specified on the command line (you can use the argparse module for this). For each file, your script should launch a child process that reads the contents and sends the contents to the parent process via a queue. The parent process should wait until all child processes are terminated, take the input from the queue, sort the results, and print them to the screen. For this assignment, you should use the argparse module for processing command line arguments. You should also use the multiprocessing module for start child processes. To send messages back to the parent process, I would recommend using multiprocessing.Manager().Queue(). You can use other Python3 modules as well as long as they are part of the standard distribution. I am including 3 data files for you to use. You do not have to include them in your submission, just your script. Below is how the final result should look like. sorter.py python3 sorter.py --files p1.dat p2.dat p3.dat AAA BBB CCC DDD EEE FFF GGG HHH III.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
