{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Dario Radečić",
  "title_listed": "Python Concurrency - A Brain-Friendly Guide for Data Professionals",
  "keywords": "并发,性能优化",
  "domain": "数据处理",
  "content_type": "深度技术解析",
  "is_paid_flag": "部分免费/会员墙",
  "url": "https://towardsdatascience.com/python-concurrency-a-brain-friendly-guide-for-data-professionals-a6215a3e9e26/",
  "publish_date": "2024-07",
  "corpus_stage": "预训练/SFT",
  "notes": "",
  "id": "f26465de354c",
  "collected_at": "2026-10-01T21:03:35",
  "title": "Python Concurrency - A Brain-Friendly Guide for Data Professionals | Towards Data Science",
  "body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Data Science](https://towardsdatascience.com/category/data-science/)\n# Python Concurrency - A Brain-Friendly Guide for Data Professionals\nMoving data around can be slow. Here's how you can squeeze every bit of performance optimization out of Python.\n[Dario Radečić](https://towardsdatascience.com/author/radecicdario/)\nJuly 26, 20249 min read\n![Photo by Matthew Brodeur on Unsplash](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/0wg1F_E6XdPmOUxFT-scaled.jpg)\nPhoto by [Matthew Brodeur](https://unsplash.com/@mrbrodeur?utm_source=medium&utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=medium&utm_medium=referral)\nPython is often criticized for being among the slowest programming languages. While that claim does hold some weight, it's vital to point out that Python is often the first programming language newcomers learn. Hence, most of the code is highly unoptimized.\nBut Python does have a couple of tricks up its sleeve. Taking advantage of concurrent function execution is stupidly simple to implement, yet it can reduce the runtime of your data pipelines tenfold. **Instead of hours, it'll take minutes**. All for free.\nToday you'll see how concurrency works in Python, and you'll also learn how to deal with exception handling, custom callbacks, and rate limiting. Let's dig in!\n* * *\n## JSON Placeholder - Your Data Source for the Day\nThe first order of business is configuring a data source. I wanted to avoid something proprietary and something that would take ages to set up. [JSON Placeholder](http://jsonplaceholder.typicode.com) - a free REST API service - is the perfect candidate.\nLearn this step by step with the interactive [AI and Data Scientist](https://roadmap.sh/ai-data-scientist) and [Data Engineer](https://roadmap.sh/data-engineer) roadmaps.\n![Image 1 - Available endpoints \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/19zPB_AFWa9s2B2FW2ijfXw.png)\nImage 1 - Available endpoints (image by author)\nTo be more precise, you'll use the `/posts/<post-id>` endpoint that returns a simple JSON object:\n![Image 2 - Sample API response \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1AMVcuxDgE_VxbtRZLQsJCQ.png)\nImage 2 - Sample API response (image by author)\nI hear you saying - _But making an API request will take a split second to finish!_ That's true, but there's always a way to slow it down.\n## Default Approach - Run Away and Never Look Back\nSince a simple API call takes a split second to run, let's make it slower to simulate a typical task in your data pipeline. The `get_post(id: int)` function will:\n  * Check for a valid `post_id`— up to 100 is considered valid\n  * Sleep for a random number of seconds between 1 and 10\n  * Make an API request to get the post, raise an error if it occurs, or return the response otherwise\n\n\nThe sleeping part makes sure the function takes a while to finish:\npython\n\n```\nimport time\nimport random\nimport requests\n\ndef get_post(post_id: int) -> dict:\n    # Value check - Posts on the API only go up to ID of 100\n    if post_id > 100:\n        raise ValueError(\"Parameter `post_id` must be less than or equal to 100\")\n\n    # API URL\n    url = f\"https://jsonplaceholder.typicode.com/posts/{post_id}\"\n\n    # Sleep to imitate a long-running process\n    time_to_sleep = random.randint(1, 10)\n    time.sleep(time_to_sleep)\n\n    # Fetch the data and return it\n    r = requests.get(url)\n    r.raise_for_status()\n    result = r.json()\n    # To indicate how much time fetching took\n    result[\"fetch_time\"] = time_to_sleep\n    # Remove the longest key-value pair for formatting reasons\n    del result[\"body\"]\n    return result\n\nif __name__ == \"__main__\":\n    print(get_post(1))\n```\n\n![Image 3 - Default approach fetch results \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1_-gQAgVhM8FganznMgvvlg.png)\nImage 3 - Default approach fetch results (image by author)\nTime to sleep is completely random, so you're likely to get a different result.\n**Things get painfully slow when you have to run this function multiple times**. Python newcomers often opt for a loop, similar to the example below:\npython\n\n```\nimport time\nimport random\nimport requests\nfrom datetime import datetime\n\ndef get_post(post_id: int) -> dict:\n    if post_id > 100:\n        raise ValueError(\"Parameter `post_id` must be less than or equal to 100\")\n\n    url = f\"https://jsonplaceholder.typicode.com/posts/{post_id}\"\n\n    time_to_sleep = random.randint(1, 10)\n    time.sleep(time_to_sleep)\n\n    r = requests.get(url)\n    r.raise_for_status()\n    result = r.json()\n    result[\"fetch_time\"] = time_to_sleep\n    del result[\"body\"]\n    return result\n\nif __name__ == \"__main__\":\n    # Measure the time\n    time_start = datetime.now()\n    print(\"Starting to fetch posts...n\")\n\n    # Simple iteration\n    for post_id in range(1, 11):\n        post = get_post(post_id)\n        print(post)\n\n    # Print total duration\n    time_end = datetime.now()\n    print(f\"nAll posts fetched! Took: {(time_end - time_start).seconds} seconds.\")\n```\n\n![Image 4 - Default approach fetch results \\(2\\) \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1PouXkxymj3GmALvvt4OlJg.png)\nImage 4 - Default approach fetch results (2) (image by author)\n53 seconds! That's the problem with sequential execution. Luckily for you, concurrency can help.\n## Say Hello to Your New Best Friend - ThreadPoolExecutor\nInstead of a traditional loop, you can use the `ThreadPoolExecutor` class, which is a high-level interface for running functions asynchronously using threads. If your machine has 8 cores, this class will run the function on 12 threads by default (number of cores + 4).\nThe `ThreadPoolExecutor` class is easy to use, and it manages a pool of worker threads for you. No manual intervention is needed.\nLet's see how it works in practice.\n### The Simplest Way to Run Tasks Concurrently in Python\nYou'll want to import `ThreadPoolExecutor` and the `as_completed()` function. The custom `get_post()` function remains unchanged.\nThe real magic happens below.\nEssentially, you're creating a new `ThreadPoolExecutor` through the context manager syntax (the most common approach). Inside, you're using the `submit()` method to add tasks to the executor. The first parameter of this method is your function name, followed by its parameter values. You can dynamically iterate over a range of values for `post_id` using Python's list comprehension.\nA `Future` object is returned by the `submit()` function.\nThe `as_completed()` function will extract and print the result as individual threads finish with execution:\npython\n\n```\nimport time\nimport random\nimport requests\nfrom datetime import datetime\n# New imports\nfrom concurrent.futures import ThreadPoolExecutor, as_completed\n\ndef get_post(post_id: int) -> dict:\n    if post_id > 100:\n        raise ValueError(\"Parameter `post_id` must be less than or equal to 100\")\n\n    url = f\"https://jsonplaceholder.typicode.com/posts/{post_id}\"\n\n    time_to_sleep = random.randint(1, 10)\n    time.sleep(time_to_sleep)\n\n    r = requests.get(url)\n    r.raise_for_status()\n    result = r.json()\n    result[\"fetch_time\"] = time_to_sleep\n    del result[\"body\"]\n    return result\n\nif __name__ == \"__main__\":\n    time_start = datetime.now()\n    print(\"Starting to fetch posts...n\")\n\n    # Run post fetching concurrently\n    with ThreadPoolExecutor() as tpe:\n        # Submit tasks and get future objects\n        futures = [tpe.submit(get_post, post_id) for post_id in range(1, 11)]\n        # Process task results\n        for future in as_completed(futures):\n            # Get and display the result\n            result = future.result()\n            print(result)\n\n    time_end = datetime.now()\n    print(f\"nAll posts fetched! Took: {(time_end - time_start).seconds} seconds.\")\n```\n\n![Image 5 - Python concurrent execution \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1AjBxX3U5Jbk5CxUgmZzImA.png)\nImage 5 - Python concurrent execution (image by author)\nWe're down to 10 seconds from 53.\n_Why 10?_ Because the longest running call to `get_post()` decided to sleep for 10 seconds. My machine has 12 CPU cores (16 `ThreadPoolExecutor` workers), meaning all tasks were submitted to the executor at the same time.\n### Scaling Things Up\nLet's now see what happens if you decide to **concurrently run more tasks than you have workers available**. Only a single line of code was changed, as indicated by the comment above:\npython\n\n```\nimport time\nimport random\nimport requests\nfrom datetime import datetime\nfrom concurrent.futures import ThreadPoolExecutor, as_completed\n\ndef get_post(post_id: int) -> dict:\n    if post_id > 100:\n        raise ValueError(\"Parameter `post_id` must be less than or equal to 100\")\n\n    url = f\"https://jsonplaceholder.typicode.com/posts/{post_id}\"\n\n    time_to_sleep = random.randint(1, 10)\n    time.sleep(time_to_sleep)\n\n    r = requests.get(url)\n    r.raise_for_status()\n    result = r.json()\n    result[\"fetch_time\"] = time_to_sleep\n    del result[\"body\"]\n    return result\n\nif __name__ == \"__main__\":\n    time_start = datetime.now()\n    print(\"Starting to fetch posts...n\")\n\n    with ThreadPoolExecutor() as tpe:\n        # Submit tasks and get future objects - NOW 100 POSTS IN TOTAL\n        futures = [tpe.submit(get_post, post_id) for post_id in range(1, 101)]\n        for future in as_completed(futures):\n            result = future.result()\n            print(result)\n\n    time_end = datetime.now()\n    print(f\"nAll posts fetched! Took: {(time_end - time_start).seconds} seconds.\")\n```\n\n![Image 6 - Python concurrent execution \\(2\\) \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1rGyvkbZph_UOfXVX2nQu3A.png)\nImage 6 - Python concurrent execution (2) (image by author)\nLong story short, `ThreadPoolExecutor` will start by running (num cores + 4) tasks at the time, and proceed with others as workers become available.\n### How to Handle Failure\nSometimes, the function you want to run concurrently will fail. Inside the `for future in as_completed(futures):` block, you can add a `try/except` block to implement exception handling.\nTo demonstrate, try submitting futures for `post_id`s up to 150 - as the `get_post()` function will raise an error for any `post_id` above 100:\npython\n\n```\nimport time\nimport random\nimport requests\nfrom datetime import datetime\nfrom concurrent.futures import ThreadPoolExecutor, as_completed\n\ndef get_post(post_id: int) -> dict:\n    if post_id > 100:\n        raise ValueError(\"Parameter `post_id` must be less than or equal to 100\")\n\n    url = f\"https://jsonplaceholder.typicode.com/posts/{post_id}\"\n\n    time_to_sleep = random.randint(1, 10)\n    time.sleep(time_to_sleep)\n\n    r = requests.get(url)\n    r.raise_for_status()\n    result = r.json()\n    result[\"fetch_time\"] = time_to_sleep\n    del result[\"body\"]\n    return result\n\nif __name__ == \"__main__\":\n    time_start = datetime.now()\n    print(\"Starting to fetch posts...n\")\n\n    with ThreadPoolExecutor() as tpe:\n        # Submit tasks and get future objects - NOW 150 POSTS IN TOTAL - 50 WILL FAIL\n        futures = [tpe.submit(get_post, post_id) for post_id in range(1, 151)]\n        # Process task results\n        for future in as_completed(futures):\n            # Your typical try/except block\n            try:\n                result = future.result()\n                print(result)\n            except Exception as e:\n                print(f\"Exception raised: {str(e)}\")\n\n    time_end = datetime.now()\n    print(f\"nAll posts fetched! Took: {(time_end - time_start).seconds} seconds.\")\n```\n\n![Image 7— Python concurrent execution \\(3\\) \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1tqAu9-_vEFsIxyknKqgvqQ.png)\nImage 7— Python concurrent execution (3) (image by author)\nYou can see that exception handling works like a charm. **The order of execution is random** , but that's irrelevant.\n### Want to Do Custom Stuff? Add Callbacks\nIn case you don't want to cram a bunch of code into the `for future in as_completed(futures):` block, you can call `add_done_callback()` to call your custom Python function. This function will have access to the `Future` object.\nThe following code snippet calls `future_callback_fn()` when execution on an individual thread finishes:\npython\n\n```\nimport time\nimport random\nimport requests\nfrom datetime import datetime\nfrom concurrent.futures import ThreadPoolExecutor, as_completed\n\ndef get_post(post_id: int) -> dict:\n    if post_id > 100:\n        raise ValueError(\"Parameter `post_id` must be less than or equal to 100\")\n\n    url = f\"https://jsonplaceholder.typicode.com/posts/{post_id}\"\n\n    time_to_sleep = random.randint(1, 10)\n    time.sleep(time_to_sleep)\n\n    r = requests.get(url)\n    r.raise_for_status()\n    result = r.json()\n    result[\"fetch_time\"] = time_to_sleep\n    del result[\"body\"]\n    return result\n\ndef future_callback_fn(future):\n    print(f\"[{datetime.now()}] Custom future callback function!\")\n    # You have access to the future object\n    print(future.result())\n\nif __name__ == \"__main__\":\n    time_start = datetime.now()\n    print(\"Starting to fetch posts...n\")\n\n    with ThreadPoolExecutor() as tpe:\n        futures = [tpe.submit(get_post, post_id) for post_id in range(1, 11)]\n        for future in as_completed(futures):\n            # Custom callback\n            future.add_done_callback(future_callback_fn)\n\n    # Print total duration\n    time_end = datetime.now()\n    print(f\"nAll posts fetched! Took: {(time_end - time_start).seconds} seconds.\")\n```\n\n![Image 8 - Python concurrent execution \\(4\\) \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1wl61Ozk12onBW2RHNafMMw.png)\nImage 8 - Python concurrent execution (4) (image by author)\nThis is a great way to keep the code inside `__main__` short and sweet.\n### Rate Limiting - How to Get Around That Pesky HTTP 429 Error\nEvery data professional works with REST APIs. While calling their endpoints concurrently is a good way to reduce the overall runtime, it can result in a`HTTP 429 Too Many Request` status.\n**The reason is simple** - the API owner doesn't want you making thousands of requests every second for the sake of performance. Or maybe, they're restricting the traffic volume based on your subscription tear.\nWhatever the case might be, an easy way around it is to install the `requests-ratelimiter` library and limit how many requests can be made per day, hour, minute, or second.\nThe example below demonstrates how to set a limit to 2 requests per second:\npython\n\n```\nimport time\nimport random\nfrom datetime import datetime\nfrom concurrent.futures import ThreadPoolExecutor, as_completed\n# New import\nfrom requests_ratelimiter import LimiterSession\n\n# Limit to max 2 calls per second\nrequest_session = LimiterSession(per_second=2)\n\ndef get_post(post_id: int) -> dict:\n    if post_id > 100:\n        raise ValueError(\"Parameter `post_id` must be less than or equal to 100\")\n\n    url = f\"https://jsonplaceholder.typicode.com/posts/{post_id}\"\n\n    time_to_sleep = random.randint(1, 10)\n    time.sleep(time_to_sleep)\n\n    # Use the request_session now\n    r = request_session.get(url)\n    r.raise_for_status()\n    result = r.json()\n    result[\"fetch_time\"] = time_to_sleep\n    del result[\"body\"]\n    return result\n\nif __name__ == \"__main__\":\n    time_start = datetime.now()\n    print(\"Starting to fetch posts...n\")\n\n    # Everything here stays the same\n    with ThreadPoolExecutor() as tpe:\n        futures = [tpe.submit(get_post, post_id) for post_id in range(1, 16)]\n        for future in as_completed(futures):\n            result = future.result()\n            print(result)\n\n    time_end = datetime.now()\n    print(f\"nAll posts fetched! Took: {(time_end - time_start).seconds} seconds.\")\n```\n\n![Image 9— Python concurrent execution \\(5\\) \\(image by author\\)](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1GqN0KRSZcD8Q8Qjbrz63wQ.png)\nImage 9— Python concurrent execution (5) (image by author)\nThe code still works flawlessly, but might take more time to finish. Still, it will be miles ahead of any sequential implementation.\n* * *\n## Summing up Python Concurrency\nConcurrency in Python requires a couple of additional lines of code, but is worth it 9/10 times. If your data pipeline fetches data from multiple sources, and the result of one fetch isn't used as an input to the other, concurrency is a guaranteed way to speed things up.\nJust imagine if you were building a web scraper that parses multiple pages with identical structures. Doing so concurrently would have a massive positive impact on the overall runtime.\nOr if you're downloading data from cloud object storage. Simply write a function to download all files in a folder, and then run it concurrently on the root folder contents.\nThe applications are endless, but it does require a bit of thinking ahead.\n**Read next:**\n> [**Python One Billion Row Challenge - From 10 Minutes to 4 Seconds**](https://towardsdatascience.com/python-one-billion-row-challenge-from-10-minutes-to-4-seconds-0718662b303e)\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657095692_93hujy.png)\nWritten By\n## [Dario Radečić](https://towardsdatascience.com/author/radecicdario/)\nhttps://writingfordevs.substack.com\n[See all from Dario Radečić](https://towardsdatascience.com/author/radecicdario/)\n[Concurrency](https://towardsdatascience.com/tag/concurrency/)[Data Engineering](https://towardsdatascience.com/tag/data-engineering/)[Data Science](https://towardsdatascience.com/tag/data-science/)[Python](https://towardsdatascience.com/tag/python/)[Towards Data Science](https://towardsdatascience.com/tag/towards-data-science/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fpython-concurrency-a-brain-friendly-guide-for-data-professionals-a6215a3e9e26%2F&title=Python%20Concurrency%20-%20A%20Brain-Friendly%20Guide%20for%20Data%20Professionals)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fpython-concurrency-a-brain-friendly-guide-for-data-professionals-a6215a3e9e26%2F&title=Python%20Concurrency%20-%20A%20Brain-Friendly%20Guide%20for%20Data%20Professionals)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fpython-concurrency-a-brain-friendly-guide-for-data-professionals-a6215a3e9e26%2F&text=Python%20Concurrency%20-%20A%20Brain-Friendly%20Guide%20for%20Data%20Professionals)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/03/1hgLY5WRr29WlnnwveYwgqw.png)](https://towardsdatascience.com/creating-choropleth-map-using-geopandas-irish-wind-energy-dataset-58dbeff913ed/)\n## [Creating choropleth map using GeoPandas - Irish wind energy dataset](https://towardsdatascience.com/creating-choropleth-map-using-geopandas-irish-wind-energy-dataset-58dbeff913ed/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nRepresenting your data of interest on a choropleth map in Python.\n[Saeed Misaghian](https://towardsdatascience.com/author/s-misaghian/)\nMarch 12, 20216 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/02/1bDKuIq065aHWaKKGEYJcPA.jpeg)](https://towardsdatascience.com/11-python-built-in-functions-you-should-know-877a2c2139db/)\n## [11 Python Built-in Functions You Should Know](https://towardsdatascience.com/11-python-built-in-functions-you-should-know-877a2c2139db/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nNo need to install, import and initialise - Just use them!\n[Christopher Tao](https://towardsdatascience.com/author/christophertao/)\nFebruary 21, 20217 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/09/1ImklV2ZcV_EpczfkTgwPvA-scaled.jpeg)](https://towardsdatascience.com/the-amo-theory-solving-the-black-box-problem-for-data-scientists-91b2d1ac9195/)\n## [The AMO theory: Solving the Black Box Problem for Data Scientists](https://towardsdatascience.com/the-amo-theory-solving-the-black-box-problem-for-data-scientists-91b2d1ac9195/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nWhen you have to explain how and why people behave in a certain way\n[Ilro Lee](https://towardsdatascience.com/author/ilro/)\nSeptember 3, 20214 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/12/1Lmri73DDQJok6s_L2gnLng.gif)](https://towardsdatascience.com/create-an-interactive-dashboard-with-shiny-flexdashboard-and-plotly-b1f025aebc9c/)\n## [Create an Interactive Dashboard with Shiny, Flexdashboard, and Plotly](https://towardsdatascience.com/create-an-interactive-dashboard-with-shiny-flexdashboard-and-plotly-b1f025aebc9c/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nA step-by-step guide to building your first interactive dashboard\n[Nata Berishvili](https://towardsdatascience.com/author/natab/)\nDecember 31, 20204 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/10/0bxsiiNOzpPGy4WOI-scaled.jpg)](https://towardsdatascience.com/common-issues-that-will-make-or-break-your-data-science-project-64e976c21a14/)\n## [Common Issues that Will Make or Break Your Data Science Project](https://towardsdatascience.com/common-issues-that-will-make-or-break-your-data-science-project-64e976c21a14/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nA helpful guide on spotting data problems, why they can be detrimental, and how to properly address them\n[Jason Chong](https://towardsdatascience.com/author/chongjason/)\nOctober 11, 202213 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/10/1dstkL37zdzOg97nhNVUvNQ.png)](https://towardsdatascience.com/version-control-101-getting-started-with-git-3b2c78d91184/)\n## [Version Control 101: Getting Started with Git](https://towardsdatascience.com/version-control-101-getting-started-with-git-3b2c78d91184/)\n[Programming](https://towardsdatascience.com/category/programming/)\nA brief overview of how Git works\n[Sara A. Metwalli](https://towardsdatascience.com/author/saraametwalli/)\nOctober 27, 20205 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/08/1xuV3oLJTfAIUJw9220PDVA-scaled.jpeg)](https://towardsdatascience.com/building-deep-neural-networks-the-easy-way-perceptilabs-bd065c9544c4/)\n## [Building Deep Neural Networks the Easy Way | Perceptilabs](https://towardsdatascience.com/building-deep-neural-networks-the-easy-way-perceptilabs-bd065c9544c4/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nA visual way of building Deep Learning Neural Networks\n[Anuj Syal](https://towardsdatascience.com/author/syal-anuj/)\nAugust 2, 20217 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/10/1UM6gWHcOMQ-FgDELFJlxVA.jpeg)](https://towardsdatascience.com/getting-started-in-data-science-means-cleaning-up-your-data-act-first-6326bcf4f33b/)\n## [Getting Started in Data Science Means Cleaning Up Your Data \"Act\" First](https://towardsdatascience.com/getting-started-in-data-science-means-cleaning-up-your-data-act-first-6326bcf4f33b/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nAn Exploratory Data Analysis (EDA) workflow for reducing clutter in data\n[Brandon Cosley](https://towardsdatascience.com/author/brandoncosley/)\nOctober 7, 202111 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/10/06b56ju6_e7rGZ2nf-scaled.jpg)](https://towardsdatascience.com/portfolio-optimization-with-numpy-93e1428525a5/)\n## [Portfolio Optimization With NumPy](https://towardsdatascience.com/portfolio-optimization-with-numpy-93e1428525a5/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nAll You Need Is Some Matrix Algebra To Make Optimal Portfolios\n[Tony Yiu](https://towardsdatascience.com/author/tonester524/)\nOctober 14, 20207 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500) How Relevance Models Foreshadowed Transformers for NLP ](https://towardsdatascience.com/how-relevance-models-foreshadowed-transformers-for-nlp/ \"How Relevance Models Foreshadowed Transformers for NLP\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500) Does Your Company Have a Data Strategy? ](https://towardsdatascience.com/does-your-company-have-a-data-strategy-e8944dbec4ae/ \"Does Your Company Have a Data Strategy?\")\n\n\n",
  "metadata": {
    "title": "Python Concurrency - A Brain-Friendly Guide for Data Professionals | Towards Data Science",
    "description": "Moving data around can be slow. Here's how you can squeeze every bit of performance optimization out of Python.",
    "keywords": null,
    "author": "Dario Radečić",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "Python Concurrency - A Brain-Friendly Guide for Data Professionals",
    "og:description": "Moving data around can be slow. Here's how you can squeeze every bit of performance optimization out of Python.",
    "og:url": "https://towardsdatascience.com/python-concurrency-a-brain-friendly-guide-for-data-professionals-a6215a3e9e26/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/0wg1F_E6XdPmOUxFT-scaled.jpg",
    "og:image:width": "2560",
    "og:image:height": "1709",
    "og:image:type": "image/jpeg",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "Dario Radečić",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "9 min read",
    "article:published_time": "2024-07-26T12:55:32.000Z",
    "article:modified_time": "2024-07-26T12:55:32.000Z",
    "article:author": "https://towardsdatascience.com/author/radecicdario/"
  },
  "paywall": {
    "listed_paid": true,
    "detected": false,
    "marker": "",
    "public_only": true,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 202,
    "error": ""
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/f26465de354c/code/block_000.txt",
      "chars": 795
    },
    {
      "language": "txt",
      "file": "attachments/f26465de354c/code/block_001.txt",
      "chars": 884
    },
    {
      "language": "txt",
      "file": "attachments/f26465de354c/code/block_002.txt",
      "chars": 1182
    },
    {
      "language": "txt",
      "file": "attachments/f26465de354c/code/block_003.txt",
      "chars": 1085
    },
    {
      "language": "txt",
      "file": "attachments/f26465de354c/code/block_004.txt",
      "chars": 1288
    },
    {
      "language": "txt",
      "file": "attachments/f26465de354c/code/block_005.txt",
      "chars": 1233
    },
    {
      "language": "txt",
      "file": "attachments/f26465de354c/code/block_006.txt",
      "chars": 1218
    }
  ],
  "images": [
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/0wg1F_E6XdPmOUxFT-scaled.jpg",
      "alt": "Photo by Matthew Brodeur on Unsplash",
      "local_path": "attachments/f26465de354c/images/000.jpg",
      "bytes": 483960,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/19zPB_AFWa9s2B2FW2ijfXw.png",
      "alt": "Image 1 - Available endpoints (image by author)",
      "local_path": "attachments/f26465de354c/images/001.png",
      "bytes": 158611,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1AMVcuxDgE_VxbtRZLQsJCQ.png",
      "alt": "Image 2 - Sample API response (image by author)",
      "local_path": "attachments/f26465de354c/images/002.png",
      "bytes": 140503,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1_-gQAgVhM8FganznMgvvlg.png",
      "alt": "Image 3 - Default approach fetch results (image by author)",
      "local_path": "attachments/f26465de354c/images/003.png",
      "bytes": 76953,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1PouXkxymj3GmALvvt4OlJg.png",
      "alt": "Image 4 - Default approach fetch results (2) (image by author)",
      "local_path": "attachments/f26465de354c/images/004.png",
      "bytes": 241852,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1AjBxX3U5Jbk5CxUgmZzImA.png",
      "alt": "Image 5 - Python concurrent execution (image by author)",
      "local_path": "attachments/f26465de354c/images/005.png",
      "bytes": 240759,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1rGyvkbZph_UOfXVX2nQu3A.png",
      "alt": "Image 6 - Python concurrent execution (2) (image by author)",
      "local_path": "attachments/f26465de354c/images/006.png",
      "bytes": 823882,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1tqAu9-_vEFsIxyknKqgvqQ.png",
      "alt": "Image 7— Python concurrent execution (3) (image by author)",
      "local_path": "attachments/f26465de354c/images/007.png",
      "bytes": 769072,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1wl61Ozk12onBW2RHNafMMw.png",
      "alt": "Image 8 - Python concurrent execution (4) (image by author)",
      "local_path": "attachments/f26465de354c/images/008.png",
      "bytes": 432636,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1GqN0KRSZcD8Q8Qjbrz63wQ.png",
      "alt": "Image 9— Python concurrent execution (5) (image by author)",
      "local_path": "attachments/f26465de354c/images/009.png",
      "bytes": 330396,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/03/1hgLY5WRr29WlnnwveYwgqw.png",
      "alt": "",
      "local_path": "attachments/f26465de354c/images/010.png",
      "bytes": 120245,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/02/1bDKuIq065aHWaKKGEYJcPA.jpeg",
      "alt": "",
      "local_path": "attachments/f26465de354c/images/011.jpeg",
      "bytes": 508337,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/09/1ImklV2ZcV_EpczfkTgwPvA-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/f26465de354c/images/012.jpeg",
      "bytes": 608091,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/12/1Lmri73DDQJok6s_L2gnLng.gif",
      "alt": "",
      "local_path": "attachments/f26465de354c/images/013.gif",
      "bytes": 2659798,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/10/0bxsiiNOzpPGy4WOI-scaled.jpg",
      "alt": "",
      "local_path": "attachments/f26465de354c/images/014.jpg",
      "bytes": 359629,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/10/1dstkL37zdzOg97nhNVUvNQ.png",
      "alt": "",
      "local_path": "attachments/f26465de354c/images/015.png",
      "bytes": 68349,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/08/1xuV3oLJTfAIUJw9220PDVA-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/f26465de354c/images/016.jpeg",
      "bytes": 449826,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/10/1UM6gWHcOMQ-FgDELFJlxVA.jpeg",
      "alt": "",
      "local_path": "attachments/f26465de354c/images/017.jpeg",
      "bytes": 111727,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/10/06b56ju6_e7rGZ2nf-scaled.jpg",
      "alt": "",
      "local_path": "attachments/f26465de354c/images/018.jpg",
      "bytes": 444291,
      "downloaded": true
    }
  ],
  "audio": [],
  "videos": [
    {
      "src": "https://www.youtube.com/c/TowardsDataScience",
      "quality": "unavailable",
      "local_path": "",
      "note": "无1080p且无720p，未交付更低清晰度"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/latest/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/editors-pick/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/the-variable/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/shipai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/submissions/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/radecicdario/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/python-one-billion-row-challenge-from-10-minutes-to-4-seconds-0718662b303e"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/concurrency/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/data-engineering/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/python/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/towards-data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/creating-choropleth-map-using-geopandas-irish-wind-energy-dataset-58dbeff913ed/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/s-misaghian/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/11-python-built-in-functions-you-should-know-877a2c2139db/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/christophertao/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/the-amo-theory-solving-the-black-box-problem-for-data-scientists-91b2d1ac9195/"
    },
    {
      "type": "external",
      "href": "https://write.insightmediagroup.io"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/company/towards-data-science/"
    },
    {
      "type": "external",
      "href": "https://x.com/TDataScience"
    },
    {
      "type": "external",
      "href": "https://unsplash.com/@mrbrodeur"
    },
    {
      "type": "external",
      "href": "https://unsplash.com"
    },
    {
      "type": "external",
      "href": "http://jsonplaceholder.typicode.com"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/ai-data-scientist"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/data-engineer"
    },
    {
      "type": "external",
      "href": "https://www.facebook.com/sharer/sharer.php?title=Python+Concurrency+-+A+Brain-Friendly+Guide+for+Data+Professionals&u=https%3A%2F%2Ftowardsdatascience.com%2Fpython-concurrency-a-brain-friendly-guide-for-data-professionals-a6215a3e9e26%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/shareArticle?mini=true&title=Python+Concurrency+-+A+Brain-Friendly+Guide+for+Data+Professionals&url=https%3A%2F%2Ftowardsdatascience.com%2Fpython-concurrency-a-brain-friendly-guide-for-data-professionals-a6215a3e9e26%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/share?text=Python+Concurrency+-+A+Brain-Friendly+Guide+for+Data+Professionals&url=https%3A%2F%2Ftowardsdatascience.com%2Fpython-concurrency-a-brain-friendly-guide-for-data-professionals-a6215a3e9e26%2F"
    },
    {
      "type": "external",
      "href": "https://www.youtube.com/c/TowardsDataScience"
    },
    {
      "type": "external",
      "href": "https://www.threads.net/@towardsdatascience"
    },
    {
      "type": "external",
      "href": "https://bsky.app/profile/towardsdatascience.com"
    },
    {
      "type": "external",
      "href": "https://thenewstack.io"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh"
    },
    {
      "type": "external",
      "href": "https://insightmediagroup.io/creator-network"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-14T11:11:48Z",
  "source_url": "https://towardsdatascience.com/python-concurrency-a-brain-friendly-guide-for-data-professionals-a6215a3e9e26/",
  "delivery_status": "excluded_paid",
  "discovery_status": "excluded_paid",
  "missing_reason": "按原约定排除付费/会员全文"
}