Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement multithreading tasks with Python

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you Python how to achieve multithreaded tasks, I hope you have something to gain after reading this article, let's discuss it together!

Read Excel data-> send it to the administrative service interface

For safety reasons, the online operation was carried out at night. At run time, it takes more than 1 second to import each piece of data, and it's crushing to think about thousands of pieces of data that start running at 10: 00 p. M.

Waiting is also dry, go downstairs to take two turns to get some air, the dirty air in the room makes people drowsy, the cold makes people awake a lot, suddenly thought of why not multi-threaded?

The first edition of multithreading and business processing programs are mixed together and are as difficult to read as shit. The next two days took some time to reconstruct several versions, separating a thread pool, iterator, and import_records.

It is much clearer, but the iterator has been exposed, requiring import_records calls to determine whether the current task is being processed by the current thread, similar to the idea of a co-program.

Exposure is good and bad, but it is basically enough for daily use and can be put aside. It's a pleasure to read books and watch movies.

Import threadingdef task_pool (thread_num, task_fn): if thread_num

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report