Boost Stock Data Download Speed with Python Threading & Queue
This tutorial shows how to combine Python's threading and Queue modules to build a producer‑consumer multithreaded downloader for Tushare stock data, dramatically reducing download time from hours to under one hour.
Using Python's threading and Queue modules, you can implement a producer‑consumer multithreaded model to accelerate the download of daily adjusted stock market data via the Tushare API.
Previously, serial downloading of adjusted data was slow and sometimes required retries; each stock requires a download step and a storage step, both of which can be parallelized.
Typical workflow
The usual pattern with queue and threading follows these steps:
Relevant Tushare interfaces
1. Stock list information
Purpose: Get basic information of listed companies on Shanghai and Shenzhen.
Method:
Result:
2. Daily adjusted market data
Purpose: Provide all historical data since listing, defaulting to forward‑adjusted.
Method:
Result:
Implementation
Producer thread – reads market data.
Consumer thread – stores data locally.
Main thread – coordinates threads.
Result: What originally took 2–3 hours now finishes in under one hour. Adding more threads yields diminishing returns because the Sina API may return HTTP 503 under high concurrency; using proxy pools and varying time windows can help.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
