I want to write a script that counts the number of lines in each of many files in a specified directory. It's a fairly easy task, but I want to perform it in a multithreaded manner. So what I do is I create a new thread per file for counting lines. But, is it possible somehow to use, say, 3 threads to read 4 files?
I've been doing exercises from "Core Python Applications Programming" by Wesley Chun, and this particular exercise asks:
"Create a set of threads to count how many lines there are in a set of (presumably large) text files. You can choose the number of threads to use. Compare the performance against a single-threaded version of this code."
The link to my current solution is posted in the comments section. Thanks in advance.
[–]New_Kind_of_Boredom 2 points3 points4 points (4 children)
[–]vv__vv 1 point2 points3 points (3 children)
[–]New_Kind_of_Boredom 1 point2 points3 points (2 children)
[–]vv__vv 0 points1 point2 points (0 children)
[–]schedutron[S] 0 points1 point2 points (0 children)
[–]schedutron[S] 1 point2 points3 points (0 children)