
Explore concurrent programming in Python, covering threading, multiprocessing, and async, with insights into CPU utilization, IO-bound vs compute-bound tasks, thread safety, race conditions, and practical tradeoffs.
Master threading in Python by creating and starting threads to run calculations and sleeps, measure timing, synchronize with join, and understand daemon threads and multiprocessing for cpu-bound tasks.
Explore turning threaded programs into reusable classes by implementing squared sum and sleepy worker classes. Manage threading with run, start, and join, and use keyword arguments for flexible initialization.
Explore concurrent programming by building a wiki worker that fetches S&P 500 symbols from Wikipedia, retrieves Yahoo Finance prices, and saves results to a database using requests and BeautifulSoup.
Set up a threaded Yahoo Finance price reader using a wiki worker to fetch S&P 500 symbols and a price worker to scrape prices with requests and lxml XPath.
Systemize symbol processing with a multiprocessing queue and a master scheduler that feeds Yahoo Finance price workers, enabling scalable, thread-safe producers and consumers for price extraction.
build a postgres insertion worker that inserts price data into a postgres prices table (id serial, symbol, price, extracted time) driven by a postgres master scheduler with an input queue.
Integrate the Postgres master scheduler into the main function, connect input and output queues, and coordinate a three-step pipeline with Yahoo Finance prices and downstream done signals.
Define and read a yaml pipelines configuration to orchestrate queues and workers for concurrent python workflows, enabling flexible, reusable data pipelines.
Learn to build a yaml-based pipeline reader that loads a yaml-defined queue of workers, initializes input and output queues, dynamically imports worker classes, and orchestrates concurrent execution.
Implement a yaml-driven concurrent pipeline by integrating a yaml pipeline executor, wiki worker, and master scheduler with queues, enabling scalable, parallel scraping and processing.
Refactor the yaml pipeline executor to run as a main worker thread, monitor progress, and only send done signals after all workers finish across downstream queues.
Clean up the program by configuring an environment via a local .env file, exporting the pipeline location and database variables, and validating with a test run for network bound threading.
Explore locking in Python threading to prevent race conditions when updating a shared counter, using lock acquire and release and a context manager for thread-safe results.
Compare threading and multiprocessing in Python for cpu-bound workloads, showing how four processes leverage multiple cores and bypass the global interpreter lock.
Discover how to distribute a cpu-bound workload across multiple processes using a queue, splitting the range into equal buckets with lower and upper bounds, and signaling completion.
Explore how to use a multiprocessing pool to parallelize simple tasks like squaring numbers, dynamically sizing pools with cpu count, and mapping inputs to a function.
Learn to pass multiple arguments to a multiprocessing pool map using Func Tools partial to fix parameters and vary the final input, like power operations.
Explore how star map enables passing multiple varying arguments to a function in a multiprocessing pool, replacing partials for multiple varying variables.
Leverage multiprocessing to count hits for values within specified lower and upper bounds in a comparison list, using star map to unpack inputs for parallel range checks.
Learn to write asynchronous programs in Python using asyncio. Define coroutines with async def, await results, and run an event loop to manage futures and concurrent tasks.
Show how to schedule multiple coroutines with create_task on the event loop to run sleeps concurrently and await results later, achieving true asynchronous concurrency.
Master how the asyncio gather method schedules coroutines to run concurrently, overlapping network waits and clarifying when to use async versus threading in web endpoints.
Capture the effect of slow or failing servers on concurrent tasks by applying asyncio.wait_for with a timeout, catching timeout errors to prevent stragglers from blocking others.
Explore asynchronous for loops in Python, using a generator and async for to yield values, await sleeps, and understand how event loops advance execution sequentially rather than concurrently.
Compare synchronous requests with asynchronous io http, showing how using async libraries and gathering tasks reduces wait times while highlighting the need for libraries that support async to avoid blocking.
Explore asynchronous waiting with asyncio wait: schedule multiple tasks, observe done and pending sets, use timeout and return_when options (all completed or first completed) to process results as they finish.
In this course you'll learn how to create multi-threaded, asynchronous, and multi-process programs in Python, so that you can make your programs run even faster.
In applications communicating with other resources, a lot of time is spent just waiting for information to be passed from one place to another. You'll learn how to use multi-threading as well as asynchronous programming to speed up programs that are heavily bottlenecked by IO operations.
We'll go through an introduction first of where potential speed bottlenecks come from as well as how we could solve these issues, and then we'll dive directly into the technical content and build out a multi-threaded program together that grabs data from the internet, parses, and saves it into a local database.
Other programs may be more heavily affected by CPU limitations. We'll also learn how to implement multiprocessing in Python, the library that lets us use multiple CPUs in our Python code. With this we'll be able to spread our workload over all the cores available on the machine we're using.
Finally, we'll also look to combine both elements, taking a look at how we can use multiprocessing together with asynchronous programming to get the most benefit for yourself, maximizing your use of CPU resources and minimizing time spent siting idle waiting for IO response.
You can find the lecture code in the GitHub repository linked in the first lesson.