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

Methods that Python custom classes inherit from threading.Thread

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "the method of inheriting threading.Thread from Python custom class". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Description

1. Multitasking program development can be completed by using threading module.

2. In order to make the encapsulation of each thread more perfect, when using the threading module, a new subclass class is usually defined, which only needs to inherit threading.Thread, and then rewrite the run method.

Example

"" use of Python multithreading "" import timeimport threading class MyThread (threading.Thread): # def _ _ init__ (self): # super (). _ init__ () def run (self): for i in range (3): time.sleep (1) msg = "Isimm" + self.name+' @'+ str (I) # name attribute What is saved is the name of the current thread print (msg) def main (): t = MyThread () t.start () if _ _ name__ = ='_ _ main__':main () "the method that the Python custom class inherits threading.Thread" ends here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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