Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement multithreading tasks with Python

Shulou Source: shulou.com Published: 2022-06-02 17:03:23 10月05日 Update

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

Tags: Threads data processing tasks articles meals transactions iterations dizziness nasty security cold fun no business done ideas interfaces quantity files Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL Microsoft NVidia Shulou Information