October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Return Thread Pool Results in Submission Order in Python

Python’s ThreadPoolExecutor can run tasks concurrently and still return results in input order. Choose map(), ordered Futures, or indexed collection with as_completed().
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Python, use ThreadPoolExecutor.map() when you want results in the same order as the input items. If you need to submit tasks individually, keep the returned futures in a list and call result() in that list’s order. Use as_completed() only when you want to handle results as tasks finish; add each result to its original index if the final collection must still be ordered.

Use Executor.map() for ordered results

map() is the most direct option when every item goes through the same function. It runs calls asynchronously, potentially concurrently, but yields results in the order of the input iterables—not the order in which tasks finish. See the Python 3.13 concurrent.futures documentation.

from concurrent.futures import ThreadPoolExecutor

def work(item):
    return process(item)

with ThreadPoolExecutor() as executor:
    results = list(executor.map(work, items))

Here, results[i] corresponds to items[i]. Converting the iterator to a list collects all results before execution continues past the block. You can also iterate over the returned iterator directly if you want to consume results one at a time while preserving input order.

Keep futures in submission order when using submit()

Use submit() when calls need different arguments or otherwise need to be created individually. Each call returns a Future. Store those futures in the order you submit them, then retrieve their results in that same order:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from concurrent.futures import ThreadPoolExecutor

with ThreadPoolExecutor() as executor:
    futures = [executor.submit(work, item) for item in items]
    results = [future.result() for future in futures]

result() waits for its future if necessary, returns its value when ready, and raises the task’s exception when that result is retrieved. Because this code waits on futures in list order, a slow earlier task can hold up access to later results that have already finished. This affects when the caller receives results, not the order in which the tasks run.

Handle results as they finish, but assemble them in order

as_completed() yields futures in completion order. To process results immediately as they become available and still build an ordered final list, associate each future with its input index, then place its value in the matching slot:

from concurrent.futures import ThreadPoolExecutor, as_completed

with ThreadPoolExecutor() as executor:
    futures = {
        executor.submit(work, item): index
        for index, item in enumerate(items)
    }
    results = [None] * len(items)

    for future in as_completed(futures):
        index = futures[future]
        results[index] = future.result()

Each completed value is handled as soon as its future finishes; after the loop, results is in input order. If None is a valid task result, the initialized slots are still unambiguous once all futures have been processed. An exception from future.result() is raised at that point, so decide whether to let it stop the loop or catch and record it for your application.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Exceptions, timeouts, and Python-version details

With map(), an exception from a task is raised when the iterator reaches that task’s result. In Python 3.13, the documented timeout is measured from the original map() call: requesting a result that has not become available within that interval raises TimeoutError. See the Python 3.13 API documentation for the precise behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Python 3.14 documentation adds buffersize to Executor.map(), limiting the number of submitted tasks whose results have not yet been yielded. The same documentation specifies that chunksize has no effect for ThreadPoolExecutor; it is not a thread-pool batching control. Check the Python 3.14 concurrent.futures documentation before using version-specific arguments.

Which pattern should you choose?

Need Pattern Ordering behavior
Same function applied to input items; ordered output executor.map(work, items) Yields results in input order
Individually configured calls; ordered output Store submit() futures in a list and call result() in list order Retrieves results in submission order; may wait behind an earlier slow task
Handle each result as soon as it finishes; ordered final collection as_completed() plus an index-to-future mapping Processes in completion order and places values into input-order slots

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.