Concurrent Downloads with Threading
Simulate downloading n files concurrently using threading, then report whether they actually ran concurrently.
Approach: start one thread per "download" (each sleeping briefly to simulate I/O wait), join them all, and compare the total elapsed time against what running them one-after-another would have taken — printing a classification rather than a raw timing value, since exact elapsed time isn't reliably reproducible across machines.
Input: One line: the number of files to "download", n.
Output: Two lines: "Downloaded <n> files", then "Concurrent" if the threads clearly ran in parallel, or "Sequential" otherwise.
3
Downloaded 3 files Concurrent
- 1 <= n <= 10
Hint 1
thread.start() begins the thread; thread.join() waits for it to finish — start all threads first, then join all of them.
Hint 2
If the downloads ran concurrently, total elapsed time should be close to one download's time (0.4s), not n times that.
Hint 3
Compare elapsed against a threshold well below the fully-sequential total (e.g. elapsed < 0.4 * n * 0.7) to classify it.
Each thread sleeps for the same short duration to simulate an I/O wait; since time.sleep() releases the GIL, all n threads make progress at once instead of one after another. Timing the whole start/join sequence and comparing it against a threshold well below what n sequential downloads would take (n * 0.4s) reliably distinguishes true concurrency from accidentally-sequential execution, without depending on an exact, non-reproducible timing value.